From f1d716871d64641136f2f7f17b0731bed59f3a12 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 18 Nov 2022 16:31:27 -0700 Subject: [PATCH] [map] Change bucket_for_hash() to item_for_hash() --- src/hb-map.hh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/hb-map.hh b/src/hb-map.hh index 66c800162..8d3d98b25 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -322,23 +322,23 @@ struct hb_hashmap_t { if (unlikely (!successful)) return false; if (unlikely ((occupancy + occupancy / 2) >= mask && !resize ())) return false; - unsigned int i = bucket_for_hash (key, hash); + item_t &item = item_for_hash (key, hash); - if (is_delete && items[i].key != key) + if (is_delete && item.key != key) return true; /* Trying to delete non-existent key. */ - if (items[i].is_used ()) + if (item.is_used ()) { occupancy--; - if (!items[i].is_tombstone ()) + if (!item.is_tombstone ()) population--; } - items[i].key = key; - items[i].value = std::forward (value); - items[i].hash = hash; - items[i].set_used (true); - items[i].set_tombstone (is_delete); + item.key = key; + item.value = std::forward (value); + item.hash = hash; + item.set_used (true); + item.set_tombstone (is_delete); occupancy++; if (!is_delete) @@ -349,10 +349,10 @@ struct hb_hashmap_t item_t& item_for (const K &key) const { - return items[bucket_for_hash (key, hb_hash (key))]; + return item_for_hash (key, hb_hash (key)); } - unsigned int bucket_for_hash (const K &key, uint32_t hash) const + item_t& item_for_hash (const K &key, uint32_t hash) const { hash &= 0x3FFFFFFF; // We only store lower 30bit of hash unsigned int i = hash % prime; @@ -361,12 +361,12 @@ struct hb_hashmap_t while (items[i].is_used ()) { if (items[i].hash == hash && items[i] == key) - return i; + return items[i]; if (tombstone == (unsigned) -1 && items[i].is_tombstone ()) tombstone = i; i = (i + ++step) & mask; } - return tombstone == (unsigned) -1 ? i : tombstone; + return items[tombstone == (unsigned) -1 ? i : tombstone]; } static unsigned int prime_for (unsigned int shift)