Changes in common/adt/hash_table.c [ad9178bf:0db0df2] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
common/adt/hash_table.c
rad9178bf r0db0df2 247 247 assert(h && h->bucket); 248 248 249 size_t idx = h->op->key_hash(key) % h->bucket_cnt; 249 size_t hash = h->op->key_hash(key); 250 size_t idx = hash % h->bucket_cnt; 250 251 251 252 list_foreach(h->bucket[idx], link, ht_link_t, 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)) { 253 if (h->op->key_equal(key, hash, cur_link)) 258 254 return cur_link; 259 }260 255 } 261 256 … … 265 260 /** Find the next item equal to item. */ 266 261 ht_link_t * 267 hash_table_find_next(const hash_table_t *h, ht_link_t * first, ht_link_t *item)262 hash_table_find_next(const hash_table_t *h, ht_link_t *item) 268 263 { 269 264 assert(item); … … 271 266 272 267 size_t idx = h->op->hash(item) % h->bucket_cnt; 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 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)) { 282 273 ht_link_t *cur_link = member_to_inst(cur, ht_link_t, link); 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)) { 274 275 if (h->op->equal(cur_link, item)) 289 276 return cur_link; 290 }291 277 } 292 278 … … 309 295 assert(!h->apply_ongoing); 310 296 311 size_t idx = h->op->key_hash(key) % h->bucket_cnt; 297 size_t hash = h->op->key_hash(key); 298 size_t idx = hash % h->bucket_cnt; 312 299 313 300 size_t removed = 0; … … 316 303 ht_link_t *cur_link = member_to_inst(cur, ht_link_t, link); 317 304 318 if (h->op->key_equal(key, cur_link)) {305 if (h->op->key_equal(key, hash, cur_link)) { 319 306 ++removed; 320 307 list_remove(cur);
Note:
See TracChangeset
for help on using the changeset viewer.