From 141368954b2ebe3e8bc1fed4599e6bd7fdefe7cc Mon Sep 17 00:00:00 2001 From: JCash Date: Sat, 28 Dec 2024 11:27:24 +0100 Subject: [PATCH] Added Hashtable::Full() --- src/jc/cpp/hashtable.h | 6 ++++++ test/hashtable.cpp | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/jc/cpp/hashtable.h b/src/jc/cpp/hashtable.h index 372dace..942c82c 100644 --- a/src/jc/cpp/hashtable.h +++ b/src/jc/cpp/hashtable.h @@ -10,6 +10,7 @@ - Supports values with = operator VERSION: + 2.11 - (2024-12-28) - Added Full() 2.10 - (2024-12-28) - Added SetCapacity() and dynamic size support 2.01 - (2016-11-06) - Removed requirement of allocating memory at power of 2 sizes 2.00 - (2016-06-04) - Changed to two arrays: entries & values @@ -300,6 +301,11 @@ class HashTable return m_Size; } + inline bool Full() const + { + return m_Size == m_Capacity; + } + class Iterator { const HashTable* m_HashTable; diff --git a/test/hashtable.cpp b/test/hashtable.cpp index b519517..c494812 100644 --- a/test/hashtable.cpp +++ b/test/hashtable.cpp @@ -434,12 +434,13 @@ TEST_F(HashTableTest, SetCapacity) { uint32_t target_size = table_size + grow_iter; - ht.SetCapacity(target_size + grow_iter); + ht.SetCapacity(target_size); FillMaps(map, ht, target_size); ASSERT_EQ(map.size(), ht.Size()); ASSERT_EQ(target_size, ht.Size()); + ASSERT_TRUE(ht.Full()); // Compare AssertEqual(map, ht);