Thu, 04 Oct 2012 19:46:10 +0200
map counts elements
ucx/map.c | file | annotate | diff | comparison | revisions | |
ucx/map.h | file | annotate | diff | comparison | revisions |
1.1 --- a/ucx/map.c Thu Oct 04 18:46:57 2012 +0200 1.2 +++ b/ucx/map.c Thu Oct 04 19:46:10 2012 +0200 1.3 @@ -8,6 +8,10 @@ 1.4 #include "map.h" 1.5 1.6 UcxMap *ucx_map_new(size_t size) { 1.7 + if(size == 0) { 1.8 + size = 16; 1.9 + } 1.10 + 1.11 UcxMap *map = (UcxMap*)malloc(sizeof(UcxMap)); 1.12 if(map == NULL) { 1.13 return NULL; 1.14 @@ -19,6 +23,7 @@ 1.15 return NULL; 1.16 } 1.17 map->size = size; 1.18 + map->count = 0; 1.19 1.20 return map; 1.21 } 1.22 @@ -40,7 +45,8 @@ 1.23 } 1.24 1.25 UcxMap *ucx_map_clone(UcxMap *map, copy_func fnc, void *data) { 1.26 - UcxMap *newmap = ucx_map_new(map->size); 1.27 + size_t bs = (map->count * 5) >> 2; 1.28 + UcxMap *newmap = ucx_map_new(bs > map->size ? bs : map->size); 1.29 UcxMapIterator i = ucx_map_iterator(map); 1.30 void *value; 1.31 UCX_MAP_FOREACH(value, i) { 1.32 @@ -86,6 +92,7 @@ 1.33 memcpy(kd, key.data, key.len); 1.34 key.data = kd; 1.35 elm->key = key; 1.36 + map->count++; 1.37 } 1.38 elm->data = data; 1.39
2.1 --- a/ucx/map.h Thu Oct 04 18:46:57 2012 +0200 2.2 +++ b/ucx/map.h Thu Oct 04 19:46:10 2012 +0200 2.3 @@ -24,6 +24,7 @@ 2.4 struct UcxMap { 2.5 UcxMapElement **map; 2.6 size_t size; 2.7 + size_t count; 2.8 }; 2.9 2.10 struct UcxKey {