Lines Matching refs:map

37 void nghttp3_map_init(nghttp3_map *map, const nghttp3_mem *mem) {
38 map->mem = mem;
39 map->tablelen = 0;
40 map->tablelenbits = 0;
41 map->table = NULL;
42 map->size = 0;
45 void nghttp3_map_free(nghttp3_map *map) {
46 if (!map) {
50 nghttp3_mem_free(map->mem, map->table);
53 void nghttp3_map_each_free(nghttp3_map *map, int (*func)(void *data, void *ptr),
58 for (i = 0; i < map->tablelen; ++i) {
59 bkt = &map->table[i];
69 int nghttp3_map_each(nghttp3_map *map, int (*func)(void *data, void *ptr),
75 if (map->size == 0) {
79 for (i = 0; i < map->tablelen; ++i) {
80 bkt = &map->table[i];
130 void nghttp3_map_print_distance(nghttp3_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));
184 static int map_resize(nghttp3_map *map, uint32_t new_tablelen,
193 nghttp3_mem_calloc(map->mem, new_tablelen, sizeof(nghttp3_map_bucket));
198 for (i = 0; i < map->tablelen; ++i) {
199 bkt = &map->table[i];
209 nghttp3_mem_free(map->mem, map->table);
210 map->tablelen = new_tablelen;
211 map->tablelenbits = new_tablelenbits;
212 map->table = new_table;
217 int nghttp3_map_insert(nghttp3_map *map, nghttp3_map_key_type key, void *data) {
223 if ((map->size + 1) * 4 > map->tablelen * 3) {
224 if (map->tablelen) {
225 rv = map_resize(map, map->tablelen * 2, map->tablelenbits + 1);
230 rv = map_resize(map, 1 << NGHTTP3_INITIAL_TABLE_LENBITS,
238 rv = insert(map->table, map->tablelen, map->tablelenbits, hash(key), key,
243 ++map->size;
247 void *nghttp3_map_find(nghttp3_map *map, nghttp3_map_key_type key) {
253 if (map->size == 0) {
258 idx = h2idx(h, map->tablelenbits);
261 bkt = &map->table[idx];
264 d > distance(map->tablelen, map->tablelenbits, bkt, idx)) {
273 idx = (idx + 1) & (map->tablelen - 1);
277 int nghttp3_map_remove(nghttp3_map *map, nghttp3_map_key_type key) {
283 if (map->size == 0) {
288 idx = h2idx(h, map->tablelenbits);
291 bkt = &map->table[idx];
294 d > distance(map->tablelen, map->tablelenbits, bkt, idx)) {
302 idx = (idx + 1) & (map->tablelen - 1);
305 bkt = &map->table[idx];
307 distance(map->tablelen, map->tablelenbits, bkt, idx) == 0) {
311 map->table[didx] = *bkt;
315 idx = (idx + 1) & (map->tablelen - 1);
318 --map->size;
324 idx = (idx + 1) & (map->tablelen - 1);
328 void nghttp3_map_clear(nghttp3_map *map) {
329 if (map->tablelen == 0) {
333 memset(map->table, 0, sizeof(*map->table) * map->tablelen);
334 map->size = 0;
337 size_t nghttp3_map_size(nghttp3_map *map) { return map->size; }