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];
130 void nghttp2_map_print_distance(nghttp2_map *map) {
135 for (i = 0; i < map->tablelen; ++i) {
136 bkt = &map->table[i];
143 idx = h2idx(bkt->hash, map->tablelenbits);
146 distance(map->tablelen, map->tablelenbits, bkt, idx));
185 static int map_resize(nghttp2_map *map, uint32_t new_tablelen,
194 nghttp2_mem_calloc(map->mem, new_tablelen, sizeof(nghttp2_map_bucket));
199 for (i = 0; i < map->tablelen; ++i) {
200 bkt = &map->table[i];
210 nghttp2_mem_free(map->mem, map->table);
211 map->tablelen = new_tablelen;
212 map->tablelenbits = new_tablelenbits;
213 map->table = new_table;
218 int nghttp2_map_insert(nghttp2_map *map, nghttp2_map_key_type key, void *data) {
224 if ((map->size + 1) * 4 > map->tablelen * 3) {
225 if (map->tablelen) {
226 rv = map_resize(map, map->tablelen * 2, map->tablelenbits + 1);
231 rv = map_resize(map, 1 << NGHTTP2_INITIAL_TABLE_LENBITS,
239 rv = insert(map->table, map->tablelen, map->tablelenbits, hash(key), key,
244 ++map->size;
248 void *nghttp2_map_find(nghttp2_map *map, nghttp2_map_key_type key) {
254 if (map->size == 0) {
259 idx = h2idx(h, map->tablelenbits);
262 bkt = &map->table[idx];
265 d > distance(map->tablelen, map->tablelenbits, bkt, idx)) {
274 idx = (idx + 1) & (map->tablelen - 1);
278 int nghttp2_map_remove(nghttp2_map *map, nghttp2_map_key_type key) {
284 if (map->size == 0) {
289 idx = h2idx(h, map->tablelenbits);
292 bkt = &map->table[idx];
295 d > distance(map->tablelen, map->tablelenbits, bkt, idx)) {
303 idx = (idx + 1) & (map->tablelen - 1);
306 bkt = &map->table[idx];
308 distance(map->tablelen, map->tablelenbits, bkt, idx) == 0) {
312 map->table[didx] = *bkt;
316 idx = (idx + 1) & (map->tablelen - 1);
319 --map->size;
325 idx = (idx + 1) & (map->tablelen - 1);
329 void nghttp2_map_clear(nghttp2_map *map) {
330 if (map->tablelen == 0) {
334 memset(map->table, 0, sizeof(*map->table) * map->tablelen);
335 map->size = 0;
338 size_t nghttp2_map_size(nghttp2_map *map) { return map->size; }