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