summaryrefslogtreecommitdiff
path: root/asl/hash_set.hpp
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2025-01-14 22:50:34 +0100
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2025-01-14 22:50:34 +0100
commit5f21ebf42e670470b315a992b8a60f7c2e2bbbeb (patch)
tree9e8408aedec5639205f13d474222b8c311ef77b7 /asl/hash_set.hpp
parent1c00f6ed444dab15430a955e41cf155049e3cec4 (diff)
Add remove element to hash_set
Diffstat (limited to 'asl/hash_set.hpp')
-rw-r--r--asl/hash_set.hpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/asl/hash_set.hpp b/asl/hash_set.hpp
index 22e47e0..fa95a96 100644
--- a/asl/hash_set.hpp
+++ b/asl/hash_set.hpp
@@ -114,6 +114,8 @@ class hash_set
isize_t find_slot(const T& value) const
{
+ if (m_size <= 0) { return -1; };
+
ASL_ASSERT(is_pow2(m_capacity));
const isize_t capacity_mask = m_capacity - 1;
@@ -246,9 +248,22 @@ public:
bool contains(const T& value) const
{
- if (m_size == 0) { return false; }
return find_slot(value) >= 0;
}
+
+ // @Todo Remove with something comparable, but not equal? How to hash?
+ // @Todo Same with contains
+ bool remove(const T& value)
+ {
+ isize_t slot = find_slot(value);
+ if (slot < 0) { return false; }
+
+ m_values[slot].destroy_unsafe(); // NOLINT(*-pointer-arithmetic)
+ m_tags[slot] = kTombstone; // NOLINT(*-pointer-arithmetic)
+ m_size -= 1;
+
+ return true;
+ }
};
} // namespace asl