Lines Matching refs:h
43 struct Curl_hash *h = (struct Curl_hash *) user; in hash_element_dtor() local
50 h->dtor(e->ptr); in hash_element_dtor()
66 Curl_hash_init(struct Curl_hash *h, in Curl_hash_init() argument
72 DEBUGASSERT(h); in Curl_hash_init()
78 h->table = NULL; in Curl_hash_init()
79 h->hash_func = hfunc; in Curl_hash_init()
80 h->comp_func = comparator; in Curl_hash_init()
81 h->dtor = dtor; in Curl_hash_init()
82 h->size = 0; in Curl_hash_init()
83 h->slots = slots; in Curl_hash_init()
85 h->init = HASHINIT; in Curl_hash_init()
108 void *Curl_hash_add2(struct Curl_hash *h, void *key, size_t key_len, void *p, in Curl_hash_add2() argument
115 DEBUGASSERT(h); in Curl_hash_add2()
116 DEBUGASSERT(h->slots); in Curl_hash_add2()
117 DEBUGASSERT(h->init == HASHINIT); in Curl_hash_add2()
118 if(!h->table) { in Curl_hash_add2()
120 h->table = malloc(h->slots * sizeof(struct Curl_llist)); in Curl_hash_add2()
121 if(!h->table) in Curl_hash_add2()
123 for(i = 0; i < h->slots; ++i) in Curl_hash_add2()
124 Curl_llist_init(&h->table[i], hash_element_dtor); in Curl_hash_add2()
127 l = FETCH_LIST(h, key, key_len); in Curl_hash_add2()
131 if(h->comp_func(he->key, he->key_len, key, key_len)) { in Curl_hash_add2()
132 Curl_node_uremove(le, (void *)h); in Curl_hash_add2()
133 --h->size; in Curl_hash_add2()
141 ++h->size; in Curl_hash_add2()
157 Curl_hash_add(struct Curl_hash *h, void *key, size_t key_len, void *p) in Curl_hash_add() argument
159 return Curl_hash_add2(h, key, key_len, p, NULL); in Curl_hash_add()
167 int Curl_hash_delete(struct Curl_hash *h, void *key, size_t key_len) in Curl_hash_delete() argument
169 DEBUGASSERT(h); in Curl_hash_delete()
170 DEBUGASSERT(h->slots); in Curl_hash_delete()
171 DEBUGASSERT(h->init == HASHINIT); in Curl_hash_delete()
172 if(h->table) { in Curl_hash_delete()
174 struct Curl_llist *l = FETCH_LIST(h, key, key_len); in Curl_hash_delete()
178 if(h->comp_func(he->key, he->key_len, key, key_len)) { in Curl_hash_delete()
179 Curl_node_uremove(le, (void *) h); in Curl_hash_delete()
180 --h->size; in Curl_hash_delete()
193 Curl_hash_pick(struct Curl_hash *h, void *key, size_t key_len) in Curl_hash_pick() argument
195 DEBUGASSERT(h); in Curl_hash_pick()
196 DEBUGASSERT(h->init == HASHINIT); in Curl_hash_pick()
197 if(h->table) { in Curl_hash_pick()
200 DEBUGASSERT(h->slots); in Curl_hash_pick()
201 l = FETCH_LIST(h, key, key_len); in Curl_hash_pick()
204 if(h->comp_func(he->key, he->key_len, key, key_len)) { in Curl_hash_pick()
221 Curl_hash_destroy(struct Curl_hash *h) in Curl_hash_destroy() argument
223 DEBUGASSERT(h->init == HASHINIT); in Curl_hash_destroy()
224 if(h->table) { in Curl_hash_destroy()
226 for(i = 0; i < h->slots; ++i) { in Curl_hash_destroy()
227 Curl_llist_destroy(&h->table[i], (void *) h); in Curl_hash_destroy()
229 Curl_safefree(h->table); in Curl_hash_destroy()
231 h->size = 0; in Curl_hash_destroy()
232 h->slots = 0; in Curl_hash_destroy()
240 Curl_hash_clean(struct Curl_hash *h) in Curl_hash_clean() argument
242 Curl_hash_clean_with_criterium(h, NULL, NULL); in Curl_hash_clean()
245 size_t Curl_hash_count(struct Curl_hash *h) in Curl_hash_count() argument
247 DEBUGASSERT(h->init == HASHINIT); in Curl_hash_count()
248 return h->size; in Curl_hash_count()
253 Curl_hash_clean_with_criterium(struct Curl_hash *h, void *user, in Curl_hash_clean_with_criterium() argument
258 if(!h || !h->table) in Curl_hash_clean_with_criterium()
261 DEBUGASSERT(h->init == HASHINIT); in Curl_hash_clean_with_criterium()
262 for(i = 0; i < h->slots; ++i) { in Curl_hash_clean_with_criterium()
263 struct Curl_llist *list = &h->table[i]; in Curl_hash_clean_with_criterium()
271 Curl_node_uremove(le, (void *) h); in Curl_hash_clean_with_criterium()
272 --h->size; /* one less entry in the hash now */ in Curl_hash_clean_with_criterium()
283 size_t h = 5381; in Curl_hash_str() local
287 h += h << 5; in Curl_hash_str()
288 h ^= j; in Curl_hash_str()
291 return (h % slots_num); in Curl_hash_str()
318 struct Curl_hash *h; in Curl_hash_next_element() local
320 h = iter->hash; in Curl_hash_next_element()
321 if(!h->table) in Curl_hash_next_element()
331 for(i = iter->slot_index; i < h->slots; i++) { in Curl_hash_next_element()
332 if(Curl_llist_head(&h->table[i])) { in Curl_hash_next_element()
333 iter->current_element = Curl_llist_head(&h->table[i]); in Curl_hash_next_element()
348 void Curl_hash_print(struct Curl_hash *h,
355 if(!h)
360 Curl_hash_start_iterate(h, &iter);
383 void Curl_hash_offt_init(struct Curl_hash *h, in Curl_hash_offt_init() argument
387 Curl_hash_init(h, slots, Curl_hash_str, Curl_str_key_compare, dtor); in Curl_hash_offt_init()
390 void *Curl_hash_offt_set(struct Curl_hash *h, curl_off_t id, void *elem) in Curl_hash_offt_set() argument
392 return Curl_hash_add(h, &id, sizeof(id), elem); in Curl_hash_offt_set()
395 int Curl_hash_offt_remove(struct Curl_hash *h, curl_off_t id) in Curl_hash_offt_remove() argument
397 return Curl_hash_delete(h, &id, sizeof(id)); in Curl_hash_offt_remove()
400 void *Curl_hash_offt_get(struct Curl_hash *h, curl_off_t id) in Curl_hash_offt_get() argument
402 return Curl_hash_pick(h, &id, sizeof(id)); in Curl_hash_offt_get()