1 import iv
.hash
.fasthash
;
3 import iv
.hash
.murhash
;
9 TESTHASH(x86, 32, 1234, "Hello, world!", "faf6cdb3");
10 TESTHASH(x86, 32, 4321, "Hello, world!", "bf505788");
11 TESTHASH(x86, 32, 1234, "xxxxxxxxxxxxxxxxxxxxxxxxxxxx", "8905ac28");
12 TESTHASH(x86, 32, 1234, "", "0f2cc00b");
15 void doHash(T
, bool norand
=false) (scope const(void)[] buf
, uint eta
, uint seed
=0) if (is(T
== struct)) {
17 if (seed
) hash
.reset(seed
);
21 while (buf
.length
> 0) {
22 import std
.random
: uniform
;
23 auto len
= uniform
!"[]"(0, buf
.length
);
24 hash
.put(buf
[0..len
]);
28 auto h
= hash
.finish32();
29 if (h
!= eta
) assert(0, T
.stringof
~" failed "~(norand ?
"initial " : "")~"streaming test");
33 void doTest(T
) (scope const(void)[] buf
, uint eta
, uint seed
=0) if (is(T
== struct)) {
35 write(T
.stringof
, ": ");
36 auto stt
= clockMilli();
37 doHash
!(T
, true)(buf
, eta
, seed
);
38 foreach (immutable _
; 0..Tries
) doHash
!T(buf
, eta
, seed
);
39 auto ett
= clockMilli()-stt
;
40 writeln(Tries
, " times took ", ett
, " milliseconds");
47 doTest
!MurHash("Hello, world!", 0xfaf6cdb3U
, 1234);
48 doTest
!MurHash("Hello, world!", 0xbf505788U
, 4321);
49 doTest
!MurHash("xxxxxxxxxxxxxxxxxxxxxxxxxxxx", 0x8905ac28U
, 1234);
50 doTest
!MurHash("", 0x0f2cc00bU
, 1234);