Fix hash_table::insert (lmao)
This commit is contained in:
parent
774620c673
commit
7c398e28ff
1 changed files with 5 additions and 0 deletions
|
|
@ -210,6 +210,11 @@ namespace psemek::util
|
||||||
template <typename H>
|
template <typename H>
|
||||||
std::pair<hash_table_iterator<T>, bool> insert(H && value)
|
std::pair<hash_table_iterator<T>, bool> insert(H && value)
|
||||||
{
|
{
|
||||||
|
// Need to make sure the key isn't present first, because
|
||||||
|
// inserting it at a tombstone can lead to duplicate keys
|
||||||
|
if (auto it = find(this->key_projector()(value)); it != end())
|
||||||
|
return {it, false};
|
||||||
|
|
||||||
ensure_capacity_for(size_ + 1);
|
ensure_capacity_for(size_ + 1);
|
||||||
std::uint64_t hash = this->hash()(this->key_projector()(value));
|
std::uint64_t hash = this->hash()(this->key_projector()(value));
|
||||||
return insert_impl(std::forward<H>(value), hash);
|
return insert_impl(std::forward<H>(value), hash);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue