public long MurmurHash3_x64_64(int key) { // Obtained by inlining MurmurHash3_x64_32(byte[], 9001) and removing all the unused code // (since we know the input is always 4 bytes and we only need 4 bytes of output) sbyte b0 = (sbyte)key; sbyte b1 = (sbyte)((uint)key >> 8); sbyte b2 = (sbyte)((uint)key >> 16); sbyte b3 = (sbyte)((uint)key >> 24); long h1 = unchecked ((long)0x9368e53c2f6af274 ^ 9001); long h2 = 0x586dcd208f7cd3fd ^ 9001; long c1 = unchecked ((long)0x87c37b91114253d5); long c2 = 0x4cf5ad432745937f; long k1 = 0; long k2 = 0; k1 ^= (long)b3 << 24; k1 ^= (long)b2 << 16; k1 ^= (long)b1 << 8; k1 ^= b0; // bmix k1 *= c1; k1 = IntHelpers.RotateLeft(k1, 23); k1 *= c2; h1 ^= k1; h1 += h2; h2 = IntHelpers.RotateLeft(h2, 41); k2 *= c2; k2 = IntHelpers.RotateLeft(k2, 23); k2 *= c1; h2 ^= k2; h2 += h1; h1 = h1 * 3 + 0x52dce729; h2 = h2 * 3 + 0x38495ab5; c1 = c1 * 5 + 0x7b7d159c; c2 = c2 * 5 + 0x6bce6396; h2 ^= 4; h1 += h2; h2 += h1; h1 = fmix64(h1); h2 = fmix64(h2); h1 += h2; h2 += h1; return(h1); }
public long MurmurHash3_x64_64(sbyte[] key, uint len, uint seed) { // Exactly the same as MurmurHash3_x64_128, except it only returns state.h1 byte[] data = (byte[])(Array)key; uint nblocks = len / 16; long h1 = unchecked ((long)0x9368e53c2f6af274 ^ seed); long h2 = 0x586dcd208f7cd3fd ^ seed; long c1 = unchecked ((long)0x87c37b91114253d5); long c2 = 0x4cf5ad432745937f; for (int i = 0; i < nblocks; i++) { long ik1 = BitConverter.ToInt64(data, (i * 2 + 0) * 8); long ik2 = BitConverter.ToInt64(data, (i * 2 + 1) * 8); // bmix ik1 *= c1; ik1 = IntHelpers.RotateLeft(ik1, 23); ik1 *= c2; h1 ^= ik1; h1 += h2; h2 = IntHelpers.RotateLeft(h2, 41); ik2 *= c2; ik2 = IntHelpers.RotateLeft(ik2, 23); ik2 *= c1; h2 ^= ik2; h2 += h1; h1 = h1 * 3 + 0x52dce729; h2 = h2 * 3 + 0x38495ab5; c1 = c1 * 5 + 0x7b7d159c; c2 = c2 * 5 + 0x6bce6396; } //---------- // tail sbyte[] tail = new sbyte[data.Length - nblocks * 16]; Buffer.BlockCopy(data, (int)nblocks * 16, tail, 0, tail.Length); long k1 = 0; long k2 = 0; switch (len & 15) { case 15: k2 ^= (long)(tail[14]) << 48; goto case 14; case 14: k2 ^= (long)(tail[13]) << 40; goto case 13; case 13: k2 ^= (long)(tail[12]) << 32; goto case 12; case 12: k2 ^= (long)(tail[11]) << 24; goto case 11; case 11: k2 ^= (long)(tail[10]) << 16; goto case 10; case 10: k2 ^= (long)(tail[9]) << 8; goto case 9; case 9: k2 ^= (long)(tail[8]) << 0; goto case 8; case 8: k1 ^= (long)(tail[7]) << 56; goto case 7; case 7: k1 ^= (long)(tail[6]) << 48; goto case 6; case 6: k1 ^= (long)(tail[5]) << 40; goto case 5; case 5: k1 ^= (long)(tail[4]) << 32; goto case 4; case 4: k1 ^= (long)(tail[3]) << 24; goto case 3; case 3: k1 ^= (long)(tail[2]) << 16; goto case 2; case 2: k1 ^= (long)(tail[1]) << 8; goto case 1; case 1: k1 ^= (long)(tail[0]) << 0; break; } ; if ((len & 15) != 0) { // bmix k1 *= c1; k1 = IntHelpers.RotateLeft(k1, 23); k1 *= c2; h1 ^= k1; h1 += h2; h2 = IntHelpers.RotateLeft(h2, 41); k2 *= c2; k2 = IntHelpers.RotateLeft(k2, 23); k2 *= c1; h2 ^= k2; h2 += h1; h1 = h1 * 3 + 0x52dce729; h2 = h2 * 3 + 0x38495ab5; c1 = c1 * 5 + 0x7b7d159c; c2 = c2 * 5 + 0x6bce6396; } //---------- // finalization h2 ^= len; h1 += h2; h2 += h1; h1 = fmix64(h1); h2 = fmix64(h2); h1 += h2; h2 += h1; return(h1); }