43 free(map->map); |
43 free(map->map); |
44 free(map); |
44 free(map); |
45 } |
45 } |
46 |
46 |
47 UcxMap *ucx_map_clone(UcxMap *map, copy_func fnc, void *data) { |
47 UcxMap *ucx_map_clone(UcxMap *map, copy_func fnc, void *data) { |
48 size_t bs = (map->count * 5) >> 2; |
48 size_t bs = (map->count * 5) >> 1; |
49 UcxMap *newmap = ucx_map_new(bs > map->size ? bs : map->size); |
49 UcxMap *newmap = ucx_map_new(bs > map->size ? bs : map->size); |
50 UcxMapIterator i = ucx_map_iterator(map); |
50 UcxMapIterator i = ucx_map_iterator(map); |
51 void *value; |
51 void *value; |
52 UCX_MAP_FOREACH(value, i) { |
52 UCX_MAP_FOREACH(value, i) { |
53 ucx_map_put(newmap, i.cur->key, fnc ? fnc(value, data) : value); |
53 ucx_map_put(newmap, i.cur->key, fnc ? fnc(value, data) : value); |
54 } |
54 } |
55 return newmap; |
55 return newmap; |
|
56 } |
|
57 |
|
58 UcxMap *ucx_map_rehash(UcxMap *map) { |
|
59 size_t load = (map->size * 3) >> 2; |
|
60 if (map->count > load) { |
|
61 UcxMap *newmap = ucx_map_clone(map, NULL, NULL); |
|
62 ucx_map_free(map); |
|
63 return newmap; |
|
64 } else { |
|
65 return map; |
|
66 } |
56 } |
67 } |
57 |
68 |
58 int ucx_map_put(UcxMap *map, UcxKey key, void *data) { |
69 int ucx_map_put(UcxMap *map, UcxKey key, void *data) { |
59 if(key.hash == 0) { |
70 if(key.hash == 0) { |
60 key.hash = ucx_hash((char*)key.data, key.len); |
71 key.hash = ucx_hash((char*)key.data, key.len); |