ucx/map.c

changeset 206
58b77eb51afd
parent 192
1e51558b9d09
child 207
1de85ecf6adc
equal deleted inserted replaced
205:54a7ceb9151f 206:58b77eb51afd
60 map->count = 0; 60 map->count = 0;
61 61
62 return map; 62 return map;
63 } 63 }
64 64
65 static void ucx_map_free_elmlist(UcxMap *map) { 65 static void ucx_map_free_elmlist_contents(UcxMap *map) {
66 for (size_t n = 0 ; n < map->size ; n++) { 66 for (size_t n = 0 ; n < map->size ; n++) {
67 UcxMapElement *elem = map->map[n]; 67 UcxMapElement *elem = map->map[n];
68 if (elem != NULL) { 68 if (elem != NULL) {
69 do { 69 do {
70 UcxMapElement *next = elem->next; 70 UcxMapElement *next = elem->next;
72 alfree(map->allocator, elem); 72 alfree(map->allocator, elem);
73 elem = next; 73 elem = next;
74 } while (elem != NULL); 74 } while (elem != NULL);
75 } 75 }
76 } 76 }
77 }
78
79 void ucx_map_free(UcxMap *map) {
80 ucx_map_free_elmlist_contents(map);
77 alfree(map->allocator, map->map); 81 alfree(map->allocator, map->map);
78 }
79
80 void ucx_map_free(UcxMap *map) {
81 ucx_map_free_elmlist(map);
82 alfree(map->allocator, map); 82 alfree(map->allocator, map);
83 }
84
85 void ucx_map_clear(UcxMap *map) {
86 ucx_map_free_elmlist_contents(map);
87 memset(map->map, 0, map->size*sizeof(UcxMapElement*));
88 map->count = 0;
83 } 89 }
84 90
85 int ucx_map_copy(UcxMap *restrict from, UcxMap *restrict to, 91 int ucx_map_copy(UcxMap *restrict from, UcxMap *restrict to,
86 copy_func fnc, void *data) { 92 copy_func fnc, void *data) {
87 UcxMapIterator i = ucx_map_iterator(from); 93 UcxMapIterator i = ucx_map_iterator(from);
122 } 128 }
123 map->count = 0; 129 map->count = 0;
124 ucx_map_copy(&oldmap, map, NULL, NULL); 130 ucx_map_copy(&oldmap, map, NULL, NULL);
125 131
126 /* free the UcxMapElement list of oldmap */ 132 /* free the UcxMapElement list of oldmap */
127 ucx_map_free_elmlist(&oldmap); 133 ucx_map_free_elmlist_contents(&oldmap);
134 alfree(map->allocator, oldmap.map);
128 } 135 }
129 return 0; 136 return 0;
130 } 137 }
131 138
132 int ucx_map_put(UcxMap *map, UcxKey key, void *data) { 139 int ucx_map_put(UcxMap *map, UcxKey key, void *data) {

mercurial