ucx/map.c

changeset 51
1c78cd19fb6b
parent 48
621a4430c404
child 52
34f50d0bada4
     1.1 --- a/ucx/map.c	Fri Oct 05 13:23:25 2012 +0200
     1.2 +++ b/ucx/map.c	Fri Oct 05 14:06:40 2012 +0200
     1.3 @@ -45,7 +45,7 @@
     1.4  }
     1.5  
     1.6  UcxMap *ucx_map_clone(UcxMap *map, copy_func fnc, void *data) {
     1.7 -    size_t bs = (map->count * 5) >> 2;
     1.8 +    size_t bs = (map->count * 5) >> 1;
     1.9      UcxMap *newmap = ucx_map_new(bs > map->size ? bs : map->size);
    1.10      UcxMapIterator i = ucx_map_iterator(map);
    1.11      void *value;
    1.12 @@ -55,6 +55,17 @@
    1.13      return newmap;
    1.14  }
    1.15  
    1.16 +UcxMap *ucx_map_rehash(UcxMap *map) {
    1.17 +    size_t load = (map->size * 3) >> 2;
    1.18 +    if (map->count > load) {
    1.19 +        UcxMap *newmap = ucx_map_clone(map, NULL, NULL);
    1.20 +        ucx_map_free(map);
    1.21 +        return newmap;
    1.22 +    } else {
    1.23 +        return map;
    1.24 +    }
    1.25 +}
    1.26 +
    1.27  int ucx_map_put(UcxMap *map, UcxKey key, void *data) {
    1.28      if(key.hash == 0) {
    1.29          key.hash = ucx_hash((char*)key.data, key.len);

mercurial