src/hash_key.c

changeset 890
54565fd74e74
parent 690
2c2304622981
equal deleted inserted replaced
889:f549fd9fbd8f 890:54565fd74e74
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; 33 const unsigned char *data = key->data;
34 if (data == NULL) { 34 if (data == NULL) {
35 // extension: special value for NULL 35 // extension: special value for NULL
36 key->hash = 1574210520u; 36 key->hash = 1574210520u;
37 return; 37 return;
38 } 38 }
79 h ^= h >> 15; 79 h ^= h >> 15;
80 80
81 key->hash = h; 81 key->hash = h;
82 } 82 }
83 83
84 CxHashKey cx_hash_key_str(char const *str) { 84 CxHashKey cx_hash_key_str(const char *str) {
85 CxHashKey key; 85 CxHashKey key;
86 key.data = str; 86 key.data = str;
87 key.len = str == NULL ? 0 : strlen(str); 87 key.len = str == NULL ? 0 : strlen(str);
88 cx_hash_murmur(&key); 88 cx_hash_murmur(&key);
89 return key; 89 return key;
90 } 90 }
91 91
92 CxHashKey cx_hash_key_bytes( 92 CxHashKey cx_hash_key_bytes(
93 unsigned char const *bytes, 93 const unsigned char *bytes,
94 size_t len 94 size_t len
95 ) { 95 ) {
96 CxHashKey key; 96 CxHashKey key;
97 key.data = bytes; 97 key.data = bytes;
98 key.len = len; 98 key.len = len;
99 cx_hash_murmur(&key); 99 cx_hash_murmur(&key);
100 return key; 100 return key;
101 } 101 }
102 102
103 CxHashKey cx_hash_key( 103 CxHashKey cx_hash_key(
104 void const *obj, 104 const void *obj,
105 size_t len 105 size_t len
106 ) { 106 ) {
107 CxHashKey key; 107 CxHashKey key;
108 key.data = obj; 108 key.data = obj;
109 key.len = len; 109 key.len = len;

mercurial