# HG changeset patch # User Olaf Wintermann # Date 1349372770 -7200 # Node ID dd03226c1a6bcd9a55fa2e2b919dd07164bee87e # Parent 46356d74e8737c7b1a027ac7ba96984bde1a2a8c map counts elements diff -r 46356d74e873 -r dd03226c1a6b ucx/map.c --- a/ucx/map.c Thu Oct 04 18:46:57 2012 +0200 +++ b/ucx/map.c Thu Oct 04 19:46:10 2012 +0200 @@ -8,6 +8,10 @@ #include "map.h" UcxMap *ucx_map_new(size_t size) { + if(size == 0) { + size = 16; + } + UcxMap *map = (UcxMap*)malloc(sizeof(UcxMap)); if(map == NULL) { return NULL; @@ -19,6 +23,7 @@ return NULL; } map->size = size; + map->count = 0; return map; } @@ -40,7 +45,8 @@ } UcxMap *ucx_map_clone(UcxMap *map, copy_func fnc, void *data) { - UcxMap *newmap = ucx_map_new(map->size); + size_t bs = (map->count * 5) >> 2; + UcxMap *newmap = ucx_map_new(bs > map->size ? bs : map->size); UcxMapIterator i = ucx_map_iterator(map); void *value; UCX_MAP_FOREACH(value, i) { @@ -86,6 +92,7 @@ memcpy(kd, key.data, key.len); key.data = kd; elm->key = key; + map->count++; } elm->data = data; diff -r 46356d74e873 -r dd03226c1a6b ucx/map.h --- a/ucx/map.h Thu Oct 04 18:46:57 2012 +0200 +++ b/ucx/map.h Thu Oct 04 19:46:10 2012 +0200 @@ -24,6 +24,7 @@ struct UcxMap { UcxMapElement **map; size_t size; + size_t count; }; struct UcxKey {