]>
Dogcows Code - chaz/yoink/blob - src/moof/hash.cc
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
10 **************************************************************************/
18 // MurmurHash2, by Austin Appleby
19 // http://murmurhash.googlepages.com/
21 // This function is in the public domain.
23 // Note - This code makes a few assumptions about how your machine behaves -
25 // 1. We can read a 4-byte value from any address without crashing
26 // 2. sizeof(int) == 4
28 // And it has a few limitations -
30 // 1. It will not work incrementally.
31 // 2. It will not produce the same results on little-endian and big-endian
34 unsigned hash_function::operator()(const void* key
, int len
,
35 unsigned int seed
) const
37 // 'm' and 'r' are mixing constants generated offline.
38 // They're not really 'magic', they just happen to work well.
40 const unsigned int m
= 0x5bd1e995;
43 // Initialize the hash to a 'random' value
45 unsigned int h
= seed
^ len
;
47 // Mix 4 bytes at a time into the hash
49 const unsigned char* data
= (const unsigned char*)key
;
53 unsigned int k
= *(unsigned int*)data
;
66 // Handle the last few bytes of the input array
70 case 3: h
^= data
[2] << 16;
71 case 2: h
^= data
[1] << 8;
76 // Do a few final mixes of the hash to ensure the last few
77 // bytes are well-incorporated.
This page took 0.049276 seconds and 4 git commands to generate.