ucx/map.c

changeset 44
46356d74e873
parent 43
02f38adea013
child 45
dd03226c1a6b
equal deleted inserted replaced
43:02f38adea013 44:46356d74e873
2 * 2 *
3 */ 3 */
4 4
5 #include <stdlib.h> 5 #include <stdlib.h>
6 #include <string.h> 6 #include <string.h>
7 #ifndef _WIN32
8 #include <unistd.h>
9 #endif /* not _WIN32 */
10 7
11 #include "map.h" 8 #include "map.h"
12 9
13 UcxMap *ucx_map_new(size_t size) { 10 UcxMap *ucx_map_new(size_t size) {
14 UcxMap *map = (UcxMap*)malloc(sizeof(UcxMap)); 11 UcxMap *map = (UcxMap*)malloc(sizeof(UcxMap));
40 } 37 }
41 free(map->map); 38 free(map->map);
42 free(map); 39 free(map);
43 } 40 }
44 41
42 UcxMap *ucx_map_clone(UcxMap *map, copy_func fnc, void *data) {
43 UcxMap *newmap = ucx_map_new(map->size);
44 UcxMapIterator i = ucx_map_iterator(map);
45 void *value;
46 UCX_MAP_FOREACH(value, i) {
47 ucx_map_put(newmap, i.cur->key, fnc ? fnc(value, data) : value);
48 }
49 return newmap;
50 }
51
45 int ucx_map_put(UcxMap *map, UcxKey key, void *data) { 52 int ucx_map_put(UcxMap *map, UcxKey key, void *data) {
46 if(key.hash == 0) { 53 if(key.hash == 0) {
47 key.hash = ucx_hash((char*)key.data, key.len); 54 key.hash = ucx_hash((char*)key.data, key.len);
48 } 55 }
49 56

mercurial