Lines Matching refs:map
37 void map_destroy(struct map *map) in map_destroy() argument
39 free(map->data); in map_destroy()
42 void map_clear(struct map *map, void (*release)(struct map_item *)) in map_clear() argument
46 for (i = 0; i < map->size; ++i){ in map_clear()
47 if (!map->data[i].item) in map_clear()
49 if (map->data[i].item != &deleted) in map_clear()
50 (* release)(map->data[i].item); in map_clear()
51 map->data[i].item = NULL; in map_clear()
53 map->count = 0; in map_clear()
56 int map_create(struct map *map) in map_create() argument
58 map->size = 0; in map_create()
59 map->data = 0; in map_create()
60 map->count = 0; in map_create()
64 static int map_hash(struct map *map, unsigned int key) in map_hash() argument
69 if (map->count == map->size) in map_hash()
72 idx = key % map->size; in map_hash()
74 for (i = 0; i < map->size; ++i) { in map_hash()
75 e = &map->data[idx]; in map_hash()
77 ++map->count; in map_hash()
83 idx = (idx + 1) % map->size; in map_hash()
89 static int map_rehash(struct map *map);
91 int map_reput(struct map *map, unsigned int key, struct map_item *value, in map_reput() argument
96 while ((rc = map_hash(map, key)) < 0) { in map_reput()
97 if ((rc = map_rehash(map)) < 0) in map_reput()
102 if (map->data[rc].item == &deleted) in map_reput()
105 *old = map->data[rc].item; in map_reput()
107 map->data[rc].item = value; in map_reput()
109 map->data[rc].item->key = key; in map_reput()
114 int map_put(struct map *map, unsigned int key, struct map_item *value) in map_put() argument
116 return map_reput(map, key, value, NULL); in map_put()
119 static int map_rehash(struct map *map) in map_rehash() argument
125 newt = calloc(sizeof(struct map_entry), map->size + 256); in map_rehash()
129 oldt = map->data; in map_rehash()
130 map->data = newt; in map_rehash()
132 o_size = map->size; in map_rehash()
133 map->size += 256; in map_rehash()
134 map->count = 0; in map_rehash()
139 rc = map_put(map, oldt[i].item->key, oldt[i].item); in map_rehash()
149 static struct map_entry *map_find(const struct map *map, unsigned int key) in map_find() argument
154 if (map->size == 0) in map_find()
157 idx = key % map->size; in map_find()
159 for (i = 0; i < map->size; ++i) { in map_find()
160 e = &map->data[idx]; in map_find()
161 idx = (idx + 1) % map->size; in map_find()
173 int map_contains(const struct map *map, unsigned int key) in map_contains() argument
175 return (map_find(map, key) == NULL) ? 0 : 1; in map_contains()
178 struct map_item *map_get(const struct map *map, unsigned int key) in map_get() argument
182 e = map_find(map, key); in map_get()
188 int map_remove(struct map *map, unsigned int key) in map_remove() argument
192 e = map_find(map, key); in map_remove()
195 --map->count; in map_remove()
200 unsigned int map_length(struct map *map) in map_length() argument
202 return map ? map->count : 0; in map_length()
205 static struct map_entry *map_iter_from(const struct map *map, unsigned int start) in map_iter_from() argument
209 for (; i < map->size; ++i) { in map_iter_from()
210 if (map->data[i].item && map->data[i].item != &deleted) in map_iter_from()
211 return &map->data[i]; in map_iter_from()
216 struct map_entry *map_iter_next(const struct map *map, struct map_entry *iter) in map_iter_next() argument
221 return map_iter_from(map, (iter - map->data) + 1); in map_iter_next()
224 struct map_entry *map_iter_first(const struct map *map) in map_iter_first() argument
226 return map_iter_from(map, 0); in map_iter_first()