src/map.c

changeset 328
2bf1da3c411e
parent 327
fbc33813265b
child 374
be77fb2da242
equal deleted inserted replaced
327:fbc33813265b 328:2bf1da3c411e
152 152
153 int ucx_map_put(UcxMap *map, UcxKey key, void *data) { 153 int ucx_map_put(UcxMap *map, UcxKey key, void *data) {
154 UcxAllocator *allocator = map->allocator; 154 UcxAllocator *allocator = map->allocator;
155 155
156 if (key.hash == 0) { 156 if (key.hash == 0) {
157 key.hash = ucx_hash(key.data, key.len); 157 key.hash = ucx_hash((const char*)key.data, key.len);
158 } 158 }
159 159
160 struct UcxMapKey mapkey; 160 struct UcxMapKey mapkey;
161 mapkey.hash = key.hash; 161 mapkey.hash = key.hash;
162 162
201 return 0; 201 return 0;
202 } 202 }
203 203
204 static void* ucx_map_get_and_remove(UcxMap *map, UcxKey key, int remove) { 204 static void* ucx_map_get_and_remove(UcxMap *map, UcxKey key, int remove) {
205 if(key.hash == 0) { 205 if(key.hash == 0) {
206 key.hash = ucx_hash((char*)key.data, key.len); 206 key.hash = ucx_hash((const char*)key.data, key.len);
207 } 207 }
208 208
209 size_t slot = key.hash%map->size; 209 size_t slot = key.hash%map->size;
210 UcxMapElement *elm = map->map[slot]; 210 UcxMapElement *elm = map->map[slot];
211 UcxMapElement *pelm = NULL; 211 UcxMapElement *pelm = NULL;
245 245
246 UcxKey ucx_key(const void *data, size_t len) { 246 UcxKey ucx_key(const void *data, size_t len) {
247 UcxKey key; 247 UcxKey key;
248 key.data = data; 248 key.data = data;
249 key.len = len; 249 key.len = len;
250 key.hash = ucx_hash(data, len); 250 key.hash = ucx_hash((const char*)data, len);
251 return key; 251 return key;
252 } 252 }
253 253
254 254
255 int ucx_hash(const char *data, size_t len) { 255 int ucx_hash(const char *data, size_t len) {

mercurial