public unsafe void Hash128PtrOverloads() { ulong seed1 = 238929482; ulong seed2 = 19384920392; string testString = "This is a test string"; ulong hash1 = seed1; ulong hash2 = seed2; fixed(void *ptr = testString) { int len = testString.Length * 2; SpookyHash.Hash128(ptr, len, ref hash1, ref hash2); HashCode128 hc = new HashCode128(hash1, hash2); Assert.Equal(hc, SpookyHash.Hash128((UIntPtr)ptr, len, seed1, seed2)); Assert.Equal(hc, SpookyHash.Hash128((UIntPtr)ptr, len, (long)seed1, (long)seed2)); Assert.Equal(hc, SpookyHash.Hash128((IntPtr)ptr, len, seed1, seed2)); Assert.Equal(hc, SpookyHash.Hash128((IntPtr)ptr, len, (long)seed1, (long)seed2)); } SpookyHash.Hash128(default(void *), 50, ref hash1, ref hash2); Assert.Equal(0UL, hash1); Assert.Equal(0UL, hash2); Assert.Equal(HashCode128.Zero, SpookyHash.Hash128(UIntPtr.Zero, 50, seed1, seed2)); Assert.Equal(HashCode128.Zero, SpookyHash.Hash128(UIntPtr.Zero, 50, (long)seed1, (long)seed2)); Assert.Equal(HashCode128.Zero, SpookyHash.Hash128(IntPtr.Zero, 50, seed1, seed2)); Assert.Equal(HashCode128.Zero, SpookyHash.Hash128(IntPtr.Zero, 50, (long)seed1, (long)seed2)); }
private static unsafe HashCode128 SpookyHash128Unchecked(string message, int startIndex, int length, ulong seed0, ulong seed1) { fixed(char *ptr = message) { SpookyHash.Hash128(ptr + startIndex, length << 1, ref seed0, ref seed1); } return(new HashCode128(seed0, seed1)); }
public unsafe void TestPieces() { byte[] bufArr = new byte[BufferSize]; for (int i = 0; i < BufferSize; ++i) { bufArr[i] = unchecked ((byte)i); } for (int i = 0; i < BufferSize; ++i) { ulong a, b, c, d, seed1 = 1, seed2 = 2; SpookyHash state = new SpookyHash(); // all as one call a = seed1; b = seed2; fixed(byte *buf = bufArr) { SpookyHash.Hash128(buf, i, ref a, ref b); } // all as one piece c = 0xdeadbeefdeadbeef; d = 0xbaceba11baceba11; state.Init(seed1, seed2); fixed(byte *buf = bufArr) { state.Update(buf, i); } state.Final(out c, out d); Assert.Equal(a, c); Assert.Equal(b, d); for (int j = 0; j < i; ++j) { c = seed1; d = seed2; state.Init(c, d); fixed(byte *buf = bufArr) { state.Update(buf, j); state.Update(buf + j, i - j); } state.Final(out c, out d); Assert.Equal(a, c); Assert.Equal(b, d); } } }
private static void HashOrig(uint n, ref ulong hash1, ref ulong hash2) { unsafe { SpookyHash.Hash128(&n, sizeof(uint), ref hash1, ref hash2); } }