Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/jc/cpp/hashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +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.10 - (2024-12-28) - Added SetCapacity(), Full() and Capacity()
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
- Removed empty key (API change)
Expand Down Expand Up @@ -301,6 +300,11 @@ class HashTable
return m_Size;
}

inline uint32_t Capacity() const
{
return m_Capacity;
}

inline bool Full() const
{
return m_Size == m_Capacity;
Expand Down
2 changes: 2 additions & 0 deletions test/hashtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,15 @@ TEST_F(HashTableTest, SetCapacity)

jc::HashTable<uint32_t, uint32_t> ht;
ht.SetCapacity(table_size);
ASSERT_EQ(table_size, ht.Capacity());

const uint32_t grow_iter_count = 20;
for (uint32_t grow_iter = 1; grow_iter < grow_iter_count; ++grow_iter)
{
uint32_t target_size = table_size + grow_iter;

ht.SetCapacity(target_size);
ASSERT_EQ(target_size, ht.Capacity());

FillMaps(map, ht, target_size);

Expand Down
Loading