diff --git a/libluna/include/luna/HashTable.h b/libluna/include/luna/HashTable.h index 243be925..ddb724c7 100644 --- a/libluna/include/luna/HashTable.h +++ b/libluna/include/luna/HashTable.h @@ -21,6 +21,10 @@ template class HashTable u64 index = hash(value, m_salt) % m_capacity; + check(m_size < m_capacity); + + // NOTE: This should not end in an infinite loop if the table is full, since the table CANNOT be full + // (should_grow() returns true before it does). The check above verifies this. while (true) { auto& bucket = m_buckets[index]; @@ -28,6 +32,9 @@ template class HashTable { if (*bucket == value) return false; index++; + if (index == m_capacity) + index = 0; // Wrap around to avoid overflowing, seems like I assumed it would do that + // automatically for some reason... (facepalm). continue; } bucket = { move(value) }; @@ -53,6 +60,7 @@ template class HashTable { if (*bucket == value) return bucket.value_ptr(); i++; + if (i == m_capacity) i = 0; } else return nullptr; @@ -82,6 +90,7 @@ template class HashTable return true; } i++; + if (i == m_capacity) i = 0; } else return false;