From 19718133368199e26fbdd9ef3eaed02337ac79d2 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 28 Feb 2024 22:35:42 +0200 Subject: [PATCH] BAN: Add HashMap::remove(iterator) --- BAN/include/BAN/HashMap.h | 22 +++++++++++----------- BAN/include/BAN/Iterators.h | 3 +++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/BAN/include/BAN/HashMap.h b/BAN/include/BAN/HashMap.h index d739c8a7e4..edbe35f232 100644 --- a/BAN/include/BAN/HashMap.h +++ b/BAN/include/BAN/HashMap.h @@ -52,6 +52,7 @@ namespace BAN ErrorOr reserve(size_type); void remove(const Key&); + void remove(iterator it); void clear(); T& operator[](const Key&); @@ -149,17 +150,16 @@ namespace BAN template void HashMap::remove(const Key& key) { - if (empty()) return; - auto& bucket = get_bucket(key); - for (auto it = bucket.begin(); it != bucket.end(); it++) - { - if (it->key == key) - { - bucket.remove(it); - m_size--; - return; - } - } + auto it = find(key); + if (it != end()) + remove(it); + } + + template + void HashMap::remove(iterator it) + { + it.outer_current()->remove(it.inner_current()); + m_size--; } template diff --git a/BAN/include/BAN/Iterators.h b/BAN/include/BAN/Iterators.h index 3c6473c536..c09ec17805 100644 --- a/BAN/include/BAN/Iterators.h +++ b/BAN/include/BAN/Iterators.h @@ -303,6 +303,9 @@ namespace BAN } } + OuterIterator outer_current() { return m_outer_current; } + InnerIterator inner_current() { return m_inner_current; } + private: OuterIterator m_outer_end; OuterIterator m_outer_current;