BAN: Add HashMap::remove(iterator)
This commit is contained in:
parent
3c88d2aad3
commit
1971813336
|
@ -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>
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue