BAN: Add HashMap::remove(iterator)

This commit is contained in:
Bananymous 2024-02-28 22:35:42 +02:00
parent 3c88d2aad3
commit 1971813336
2 changed files with 14 additions and 11 deletions

View File

@ -52,6 +52,7 @@ namespace BAN
ErrorOr<void> reserve(size_type); ErrorOr<void> reserve(size_type);
void remove(const Key&); void remove(const Key&);
void remove(iterator it);
void clear(); void clear();
T& operator[](const Key&); T& operator[](const Key&);
@ -149,17 +150,16 @@ namespace BAN
template<typename Key, typename T, typename HASH> template<typename Key, typename T, typename HASH>
void HashMap<Key, T, HASH>::remove(const Key& key) void HashMap<Key, T, HASH>::remove(const Key& key)
{ {
if (empty()) return; auto it = find(key);
auto& bucket = get_bucket(key); if (it != end())
for (auto it = bucket.begin(); it != bucket.end(); it++) remove(it);
{ }
if (it->key == key)
{ template<typename Key, typename T, typename HASH>
bucket.remove(it); void HashMap<Key, T, HASH>::remove(iterator it)
m_size--; {
return; it.outer_current()->remove(it.inner_current());
} m_size--;
}
} }
template<typename Key, typename T, typename HASH> template<typename Key, typename T, typename HASH>

View File

@ -303,6 +303,9 @@ namespace BAN
} }
} }
OuterIterator outer_current() { return m_outer_current; }
InnerIterator inner_current() { return m_inner_current; }
private: private:
OuterIterator m_outer_end; OuterIterator m_outer_end;
OuterIterator m_outer_current; OuterIterator m_outer_current;