| 80 h ^= h >> 15; |
80 h ^= h >> 15; |
| 81 |
81 |
| 82 key->hash = h; |
82 key->hash = h; |
| 83 } |
83 } |
| 84 |
84 |
| 85 |
|
| 86 uint32_t cx_hash_u32(uint32_t x) { |
|
| 87 x = ((x >> 16) ^ x) * 0x45d9f3bu; |
|
| 88 x = ((x >> 16) ^ x) * 0x45d9f3bu; |
|
| 89 x = (x >> 16) ^ x; |
|
| 90 return x; |
|
| 91 } |
|
| 92 |
|
| 93 uint64_t cx_hash_u64(uint64_t x) { |
|
| 94 x = (x ^ (x >> 30)) * UINT64_C(0xbf58476d1ce4e5b9); |
|
| 95 x = (x ^ (x >> 27)) * UINT64_C(0x94d049bb133111eb); |
|
| 96 x = x ^ (x >> 31); |
|
| 97 return x; |
|
| 98 } |
|
| 99 |
|
| 100 CxHashKey cx_hash_key_str(const char *str) { |
|
| 101 CxHashKey key; |
|
| 102 key.data = str; |
|
| 103 key.len = str == NULL ? 0 : strlen(str); |
|
| 104 cx_hash_murmur(&key); |
|
| 105 return key; |
|
| 106 } |
|
| 107 |
|
| 108 CxHashKey cx_hash_key_ustr(unsigned const char *str) { |
|
| 109 CxHashKey key; |
|
| 110 key.data = str; |
|
| 111 key.len = str == NULL ? 0 : strlen((const char*)str); |
|
| 112 cx_hash_murmur(&key); |
|
| 113 return key; |
|
| 114 } |
|
| 115 |
|
| 116 CxHashKey cx_hash_key_cxstr(cxstring str) { |
|
| 117 return cx_hash_key(str.ptr, str.length); |
|
| 118 } |
|
| 119 |
|
| 120 CxHashKey cx_hash_key_mutstr(cxmutstr str) { |
|
| 121 return cx_hash_key(str.ptr, str.length); |
|
| 122 } |
|
| 123 |
|
| 124 CxHashKey cx_hash_key_bytes( |
|
| 125 const unsigned char *bytes, |
|
| 126 size_t len |
|
| 127 ) { |
|
| 128 CxHashKey key; |
|
| 129 key.data = bytes; |
|
| 130 key.len = len; |
|
| 131 cx_hash_murmur(&key); |
|
| 132 return key; |
|
| 133 } |
|
| 134 |
|
| 135 CxHashKey cx_hash_key( |
85 CxHashKey cx_hash_key( |
| 136 const void *obj, |
86 const void *obj, |
| 137 size_t len |
87 size_t len |
| 138 ) { |
88 ) { |
| 139 CxHashKey key; |
89 CxHashKey key; |
| 140 key.data = obj; |
90 key.data = obj; |
| 141 key.len = len; |
91 key.len = len; |
| 142 cx_hash_murmur(&key); |
92 cx_hash_murmur(&key); |
| 143 return key; |
|
| 144 } |
|
| 145 |
|
| 146 CxHashKey cx_hash_key_u32(uint32_t x) { |
|
| 147 CxHashKey key; |
|
| 148 key.data = NULL; |
|
| 149 key.len = 0; |
|
| 150 key.hash = cx_hash_u32(x); |
|
| 151 return key; |
|
| 152 } |
|
| 153 |
|
| 154 CxHashKey cx_hash_key_u64(uint64_t x) { |
|
| 155 CxHashKey key; |
|
| 156 key.data = NULL; |
|
| 157 key.len = 0; |
|
| 158 key.hash = cx_hash_u64(x); |
|
| 159 return key; |
93 return key; |
| 160 } |
94 } |
| 161 |
95 |
| 162 int cx_hash_key_cmp(const void *l, const void *r) { |
96 int cx_hash_key_cmp(const void *l, const void *r) { |
| 163 const CxHashKey *left = l; |
97 const CxHashKey *left = l; |