Changes in common/adt/hash_table.c [0db0df2:ad9178bf] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
common/adt/hash_table.c
r0db0df2 rad9178bf 247 247 assert(h && h->bucket); 248 248 249 size_t hash = h->op->key_hash(key); 250 size_t idx = hash % h->bucket_cnt; 249 size_t idx = h->op->key_hash(key) % h->bucket_cnt; 251 250 252 251 list_foreach(h->bucket[idx], link, ht_link_t, cur_link) { 253 if (h->op->key_equal(key, hash, cur_link)) 252 /* 253 * Is this is the item we are looking for? We could have first 254 * checked if the hashes match but op->key_equal() may very well be 255 * just as fast as op->hash(). 256 */ 257 if (h->op->key_equal(key, cur_link)) { 254 258 return cur_link; 259 } 255 260 } 256 261 … … 260 265 /** Find the next item equal to item. */ 261 266 ht_link_t * 262 hash_table_find_next(const hash_table_t *h, ht_link_t * item)267 hash_table_find_next(const hash_table_t *h, ht_link_t *first, ht_link_t *item) 263 268 { 264 269 assert(item); … … 266 271 267 272 size_t idx = h->op->hash(item) % h->bucket_cnt; 268 list_t *list = &h->bucket[idx]; 269 link_t *cur = list_next(&item->link, list); 270 271 /* Traverse the list until we reach its end. */ 272 for (; cur != NULL; cur = list_next(cur, list)) { 273 274 /* Traverse the circular list until we reach the starting item again. */ 275 for (link_t *cur = item->link.next; cur != &first->link; 276 cur = cur->next) { 277 assert(cur); 278 279 if (cur == &h->bucket[idx].head) 280 continue; 281 273 282 ht_link_t *cur_link = member_to_inst(cur, ht_link_t, link); 274 275 if (h->op->equal(cur_link, item)) 283 /* 284 * Is this is the item we are looking for? We could have first 285 * checked if the hashes match but op->equal() may very well be 286 * just as fast as op->hash(). 287 */ 288 if (h->op->equal(cur_link, item)) { 276 289 return cur_link; 290 } 277 291 } 278 292 … … 295 309 assert(!h->apply_ongoing); 296 310 297 size_t hash = h->op->key_hash(key); 298 size_t idx = hash % h->bucket_cnt; 311 size_t idx = h->op->key_hash(key) % h->bucket_cnt; 299 312 300 313 size_t removed = 0; … … 303 316 ht_link_t *cur_link = member_to_inst(cur, ht_link_t, link); 304 317 305 if (h->op->key_equal(key, hash,cur_link)) {318 if (h->op->key_equal(key, cur_link)) { 306 319 ++removed; 307 320 list_remove(cur);
Note:
See TracChangeset
for help on using the changeset viewer.