Lines Matching refs:map

36 void nghttp2_map_init(nghttp2_map *map, nghttp2_mem *mem) {
37 map->mem = mem;
38 map->tablelen = 0;
39 map->tablelenbits = 0;
40 map->table = NULL;
41 map->size = 0;
44 void nghttp2_map_free(nghttp2_map *map) {
45 if (!map) {
49 nghttp2_mem_free(map->mem, map->table);
52 void nghttp2_map_each_free(nghttp2_map *map, int (*func)(void *data, void *ptr),
57 for (i = 0; i < map->tablelen; ++i) {
58 bkt = &map->table[i];
68 int nghttp2_map_each(nghttp2_map *map, int (*func)(void *data, void *ptr),
74 if (map->size == 0) {
78 for (i = 0; i < map->tablelen; ++i) {
79 bkt = &map->table[i];
129 void nghttp2_map_print_distance(nghttp2_map *map) {
134 for (i = 0; i < map->tablelen; ++i) {
135 bkt = &map->table[i];
142 idx = h2idx(bkt->hash, map->tablelenbits);
145 distance(map->tablelen, map->tablelenbits, bkt, idx));
183 static int map_resize(nghttp2_map *map, uint32_t new_tablelen,
192 nghttp2_mem_calloc(map->mem, new_tablelen, sizeof(nghttp2_map_bucket));
197 for (i = 0; i < map->tablelen; ++i) {
198 bkt = &map->table[i];
208 nghttp2_mem_free(map->mem, map->table);
209 map->tablelen = new_tablelen;
210 map->tablelenbits = new_tablelenbits;
211 map->table = new_table;
216 int nghttp2_map_insert(nghttp2_map *map, nghttp2_map_key_type key, void *data) {
222 if ((map->size + 1) * 4 > map->tablelen * 3) {
223 if (map->tablelen) {
224 rv = map_resize(map, map->tablelen * 2, map->tablelenbits + 1);
229 rv = map_resize(map, 1 << NGHTTP2_INITIAL_TABLE_LENBITS,
237 rv = insert(map->table, map->tablelen, map->tablelenbits, hash(key), key,
242 ++map->size;
246 void *nghttp2_map_find(nghttp2_map *map, nghttp2_map_key_type key) {
252 if (map->size == 0) {
257 idx = h2idx(h, map->tablelenbits);
260 bkt = &map->table[idx];
263 d > distance(map->tablelen, map->tablelenbits, bkt, idx)) {
272 idx = (idx + 1) & (map->tablelen - 1);
276 int nghttp2_map_remove(nghttp2_map *map, nghttp2_map_key_type key) {
282 if (map->size == 0) {
287 idx = h2idx(h, map->tablelenbits);
290 bkt = &map->table[idx];
293 d > distance(map->tablelen, map->tablelenbits, bkt, idx)) {
301 idx = (idx + 1) & (map->tablelen - 1);
304 bkt = &map->table[idx];
306 distance(map->tablelen, map->tablelenbits, bkt, idx) == 0) {
310 map->table[didx] = *bkt;
314 idx = (idx + 1) & (map->tablelen - 1);
317 --map->size;
323 idx = (idx + 1) & (map->tablelen - 1);
327 void nghttp2_map_clear(nghttp2_map *map) {
328 if (map->tablelen == 0) {
332 memset(map->table, 0, sizeof(*map->table) * map->tablelen);
333 map->size = 0;
336 size_t nghttp2_map_size(nghttp2_map *map) { return map->size; }