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);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Key, typename T, typename HASH>
|
||||||
|
void HashMap<Key, T, HASH>::remove(iterator it)
|
||||||
{
|
{
|
||||||
if (it->key == key)
|
it.outer_current()->remove(it.inner_current());
|
||||||
{
|
|
||||||
bucket.remove(it);
|
|
||||||
m_size--;
|
m_size--;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Key, typename T, typename HASH>
|
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:
|
private:
|
||||||
OuterIterator m_outer_end;
|
OuterIterator m_outer_end;
|
||||||
OuterIterator m_outer_current;
|
OuterIterator m_outer_current;
|
||||||
|
|
Loading…
Reference in New Issue