Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • common/adt/hash_table.c

    rad9178bf r0db0df2  
    247247        assert(h && h->bucket);
    248248
    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;
    250251
    251252        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))
    258254                        return cur_link;
    259                 }
    260255        }
    261256
     
    265260/** Find the next item equal to item. */
    266261ht_link_t *
    267 hash_table_find_next(const hash_table_t *h, ht_link_t *first, ht_link_t *item)
     262hash_table_find_next(const hash_table_t *h, ht_link_t *item)
    268263{
    269264        assert(item);
     
    271266
    272267        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)) {
    282273                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))
    289276                        return cur_link;
    290                 }
    291277        }
    292278
     
    309295        assert(!h->apply_ongoing);
    310296
    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;
    312299
    313300        size_t removed = 0;
     
    316303                ht_link_t *cur_link = member_to_inst(cur, ht_link_t, link);
    317304
    318                 if (h->op->key_equal(key, cur_link)) {
     305                if (h->op->key_equal(key, hash, cur_link)) {
    319306                        ++removed;
    320307                        list_remove(cur);
Note: See TracChangeset for help on using the changeset viewer.