diff --git a/AK/HashTable.h b/AK/HashTable.h index 185f9cc7c9..fbfc25fe3b 100644 --- a/AK/HashTable.h +++ b/AK/HashTable.h @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -59,6 +60,8 @@ private: , m_is_end(is_end) , m_bucket_iterator(bucket_iterator) { + ASSERT(!table.m_clearing); + ASSERT(!table.m_rehashing); if (!is_end && !m_table.is_empty() && !(m_bucket_iterator != BucketIteratorType::universal_end())) { m_bucket_iterator = m_table.bucket(0).begin(); if (m_bucket_iterator.is_end()) @@ -146,7 +149,6 @@ public: ConstIterator begin() const { return ConstIterator(*this, is_empty()); } ConstIterator end() const { return ConstIterator(*this, true); } - template Iterator find(unsigned hash, Finder finder) { @@ -221,6 +223,8 @@ private: int m_size { 0 }; int m_capacity { 0 }; + bool m_clearing { false }; + bool m_rehashing { false }; }; template @@ -268,6 +272,7 @@ void HashTable::set(const T& value) template void HashTable::rehash(int new_capacity) { + TemporaryChange change(m_rehashing, true); new_capacity *= 2; auto* new_buckets = new Bucket[new_capacity]; auto* old_buckets = m_buckets; @@ -287,6 +292,7 @@ void HashTable::rehash(int new_capacity) template void HashTable::clear() { + TemporaryChange change(m_clearing, true); if (m_buckets) { delete[] m_buckets; m_buckets = nullptr;