Me@14: Me@14: /*This file is sample code pulled off the web -- NOT part of the compiled code Me@14: * make sure it doesn't get included in makefile 'cause it doesn't compile Me@14: */ Me@14: Me@14: //----------------------------------------------------------------------------- Me@14: // MurmurHash2, by Austin Appleby Me@14: Me@14: // Note - This code makes a few assumptions about how your machine behaves - Me@14: Me@14: // 1. We can read a 4-byte value from any address without crashing Me@14: // 2. sizeof(int) == 4 Me@14: Me@14: // And it has a few limitations - Me@14: Me@14: // 1. It will not work incrementally. Me@14: // 2. It will not produce the same results on little-endian and big-endian Me@14: // machines. Me@14: Me@14: unsigned int MurmurHash2 ( const void * key, int len, unsigned int seed ) Me@14: { Me@14: // 'm' and 'r' are mixing constants generated offline. Me@14: // They're not really 'magic', they just happen to work well. Me@14: Me@14: const unsigned int m = 0x5bd1e995; Me@14: const int r = 24; Me@14: Me@14: // Initialize the hash to a 'random' value Me@14: Me@14: unsigned int h = seed ^ len; Me@14: Me@14: // Mix 4 bytes at a time into the hash Me@14: Me@14: const unsigned char * data = (const unsigned char *)key; Me@14: Me@14: while(len >= 4) Me@14: { Me@14: unsigned int k = *(unsigned int *)data; Me@14: Me@14: k *= m; Me@14: k ^= k >> r; Me@14: k *= m; Me@14: Me@14: h *= m; Me@14: h ^= k; Me@14: Me@14: data += 4; Me@14: len -= 4; Me@14: } Me@14: Me@14: // Handle the last few bytes of the input array Me@14: Me@14: switch(len) Me@14: { Me@14: case 3: h ^= data[2] << 16; Me@14: case 2: h ^= data[1] << 8; Me@14: case 1: h ^= data[0]; Me@14: h *= m; Me@14: }; Me@14: Me@14: // Do a few final mixes of the hash to ensure the last few Me@14: // bytes are well-incorporated. Me@14: Me@14: h ^= h >> 13; Me@14: h *= m; Me@14: h ^= h >> 15; Me@14: Me@14: return h; Me@14: }