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);
void remove(const Key&);
void remove(iterator it);
void clear();
T& operator[](const Key&);
@ -149,17 +150,16 @@ namespace BAN
template<typename Key, typename T, typename HASH>
void HashMap<Key, T, HASH>::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<typename Key, typename T, typename HASH>
void HashMap<Key, T, HASH>::remove(iterator it)
{
it.outer_current()->remove(it.inner_current());
m_size--;
}
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:
OuterIterator m_outer_end;
OuterIterator m_outer_current;