src/hash_key.c

changeset 604
056e5f592d84
parent 603
c49104015a6b
child 628
1e2be40f0cb5
equal deleted inserted replaced
603:c49104015a6b 604:056e5f592d84
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;
77 } 82 }
78 83
79 CxHashKey cx_hash_key_str(char const *str) { 84 CxHashKey cx_hash_key_str(char const *str) {
80 CxHashKey key; 85 CxHashKey key;
81 key.data.cstr = str; 86 key.data.cstr = str;
82 key.len = str == NULL ? 0 : (1 + strlen(str)); 87 key.len = str == NULL ? 0 : strlen(str);
83 cx_hash_murmur(&key); 88 cx_hash_murmur(&key);
84 return key; 89 return key;
85 } 90 }
86 91
87 CxHashKey cx_hash_key_bytes( 92 CxHashKey cx_hash_key_bytes(

mercurial