projects
/
awesomized
/
libmemcached
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
history
|
raw
|
HEAD
Fixes for previous merges (and additional file added for murmur)
[awesomized/libmemcached]
/
lib
/
murmur_hash.c
1
#include
"common.h"
2
3
/*
4
"Murmur"hash provided by Austin, tanjent@gmail.com
5
#define MURMUR_POSTMIX
6
*/
7
8
uint32_t
murmur_hash
(
char
*
key
,
size_t
length
)
9
{
10
const unsigned int
m
=
0x7fd652ad
;
11
const int
r
=
16
;
12
13
uint32_t
h
=
0xdeadbeef
;
14
15
while
(
length
>=
4
)
16
{
17
h
+= *(
unsigned int
*)
key
;
18
h
*=
m
;
19
h
^=
h
>>
r
;
20
21
key
+=
4
;
22
length
-=
4
;
23
}
24
25
switch
(
length
)
26
{
27
case
3
:
28
h
+=
key
[
2
] <<
16
;
29
case
2
:
30
h
+=
key
[
1
] <<
8
;
31
case
1
:
32
default
:
33
h
+=
key
[
0
];
34
h
*=
m
;
35
h
^=
h
>>
r
;
36
};
37
38
#ifdef MURMUR_POSTMIX
39
40
h
*=
m
;
41
h
^=
h
>>
10
;
42
h
*=
m
;
43
h
^=
h
>>
17
;
44
45
#endif
46
47
return
h
;
48
}