src/ucx/hash_key.c

changeset 416
e2093ca0ef90
parent 415
d938228c382e
child 438
22eca559aded
equal deleted inserted replaced
415:d938228c382e 416:e2093ca0ef90
28 28
29 #include "cx/hash_key.h" 29 #include "cx/hash_key.h"
30 #include <string.h> 30 #include <string.h>
31 31
32 void cx_hash_murmur(CxHashKey *key) { 32 void cx_hash_murmur(CxHashKey *key) {
33 unsigned char const *data = key->data.cbytes;
34 if (data == NULL) {
35 /* extension: special value for NULL */
36 key->hash = 1574210520u;
37 return;
38 }
33 size_t len = key->len; 39 size_t len = key->len;
34 unsigned char const *data = key->data.cbytes;
35 40
36 unsigned m = 0x5bd1e995; 41 unsigned m = 0x5bd1e995;
37 unsigned r = 24; 42 unsigned r = 24;
38 unsigned h = 25 ^ len; 43 unsigned h = 25 ^ len;
39 unsigned i = 0; 44 unsigned i = 0;
94 cx_hash_murmur(&key); 99 cx_hash_murmur(&key);
95 return key; 100 return key;
96 } 101 }
97 102
98 CxHashKey cx_hash_key( 103 CxHashKey cx_hash_key(
99 void *obj, 104 void const *obj,
100 size_t len 105 size_t len
101 ) { 106 ) {
102 CxHashKey key; 107 CxHashKey key;
103 key.data.obj = obj; 108 key.data.cobj = obj;
104 key.len = len; 109 key.len = len;
105 cx_hash_murmur(&key); 110 cx_hash_murmur(&key);
106 return key; 111 return key;
107 } 112 }

mercurial