From 7c398e28ff5832b3c56ade9f2658681d6c4dbdeb Mon Sep 17 00:00:00 2001 From: lisyarus Date: Thu, 13 Nov 2025 12:42:33 +0300 Subject: [PATCH] Fix hash_table::insert (lmao) --- libs/util/include/psemek/util/hash_table.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/util/include/psemek/util/hash_table.hpp b/libs/util/include/psemek/util/hash_table.hpp index 00463c09..f5989f0f 100644 --- a/libs/util/include/psemek/util/hash_table.hpp +++ b/libs/util/include/psemek/util/hash_table.hpp @@ -210,6 +210,11 @@ namespace psemek::util template std::pair, 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); std::uint64_t hash = this->hash()(this->key_projector()(value)); return insert_impl(std::forward(value), hash);