[map] Return success from ->set()

This commit is contained in:
Behdad Esfahbod 2021-03-29 18:12:05 -06:00
parent 8741914a80
commit a8f9f85a91

View File

@ -140,9 +140,9 @@ struct hb_hashmap_t
return true;
}
void set (K key, V value)
bool set (K key, V value)
{
set_with_hash (key, hb_hash (key), value);
return set_with_hash (key, hb_hash (key), value);
}
V get (K key) const
@ -211,15 +211,15 @@ struct hb_hashmap_t
protected:
void set_with_hash (K key, uint32_t hash, V value)
bool set_with_hash (K key, uint32_t hash, V value)
{
if (unlikely (!successful)) return;
if (unlikely (key == kINVALID)) return;
if ((occupancy + occupancy / 2) >= mask && !resize ()) return;
if (unlikely (!successful)) return false;
if (unlikely (key == kINVALID)) return true;
if (unlikely ((occupancy + occupancy / 2) >= mask && !resize ())) return false;
unsigned int i = bucket_for_hash (key, hash);
if (value == vINVALID && items[i].key != key)
return; /* Trying to delete non-existent key. */
return true; /* Trying to delete non-existent key. */
if (!items[i].is_unused ())
{
@ -235,6 +235,8 @@ struct hb_hashmap_t
occupancy++;
if (!items[i].is_tombstone ())
population++;
return true;
}
unsigned int bucket_for (K key) const