mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:37:35 +00:00
Add HashTable::remove() and fix a bug where ConstIterator would skip the first.
This commit is contained in:
parent
f794190de0
commit
c2ef54c044
2 changed files with 48 additions and 3 deletions
|
@ -186,12 +186,12 @@ public:
|
|||
{
|
||||
if (!isEnd && !m_table.isEmpty() && !(m_bucketIterator != DoublyLinkedList<T>::ConstIterator::universalEnd())) {
|
||||
#ifdef HASHTABLE_DEBUG
|
||||
printf("bucket iterator init!\n");
|
||||
printf("const bucket iterator init!\n");
|
||||
#endif
|
||||
const DoublyLinkedList<T>& chain = m_table.m_buckets[0].chain;
|
||||
m_bucketIterator = chain.begin();
|
||||
|
||||
skipToNext();
|
||||
if (m_bucketIterator.isEnd())
|
||||
skipToNext();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -207,6 +207,15 @@ public:
|
|||
Iterator find(const T&);
|
||||
ConstIterator find(const T&) const;
|
||||
|
||||
void remove(const T& value)
|
||||
{
|
||||
auto it = find(value);
|
||||
if (it != end())
|
||||
remove(it);
|
||||
}
|
||||
|
||||
void remove(Iterator&);
|
||||
|
||||
private:
|
||||
Bucket& lookup(const T&);
|
||||
const Bucket& lookup(const T&) const;
|
||||
|
@ -315,6 +324,14 @@ auto HashTable<T, TraitsForT>::find(const T& value) const -> ConstIterator
|
|||
return end();
|
||||
}
|
||||
|
||||
template<typename T, typename TraitsForT>
|
||||
void HashTable<T, TraitsForT>::remove(Iterator& it)
|
||||
{
|
||||
ASSERT(!isEmpty());
|
||||
m_buckets[it.m_bucketIndex].chain.remove(it.m_bucketIterator);
|
||||
--m_size;
|
||||
}
|
||||
|
||||
template<typename T, typename TraitsForT>
|
||||
typename HashTable<T, TraitsForT>::Bucket& HashTable<T, TraitsForT>::lookup(const T& value)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue