fix: resize of Table.Drop() now decreases size

- Generalized Table.resize() to accept a capacity size for each bucket.
This commit is contained in:
2026-03-19 20:01:50 -04:00
parent 74ed81761c
commit c1314f8a3c
3 changed files with 27 additions and 14 deletions

View File

@@ -64,7 +64,7 @@ func TestStartingCapacity(t *testing.T) {
assert := assert.New(t)
table := cuckoo.NewTable[int, bool](cuckoo.Capacity(64))
assert.Equal(uint64(128), table.Capacity())
assert.Equal(uint64(128), table.TotalCapacity())
}
func TestResizeCapacity(t *testing.T) {
@@ -74,12 +74,12 @@ func TestResizeCapacity(t *testing.T) {
cuckoo.GrowthFactor(2),
)
for table.Capacity() == 16 {
for table.TotalCapacity() == 16 {
err := table.Put(rand.Int(), true)
assert.NoError(err)
}
assert.Equal(uint64(32), table.Capacity())
assert.Equal(uint64(32), table.TotalCapacity())
}
func TestPutMany(t *testing.T) {
@@ -128,3 +128,16 @@ func TestRemove(t *testing.T) {
assert.True(table.Has(0))
}
func TestDropItem(t *testing.T) {
assert := assert.New(t)
key, value := 0, true
table := cuckoo.NewTable[int, bool]()
(table.Put(key, value))
err := table.Drop(key)
assert.NoError(err)
assert.Equal(0, table.Size())
assert.False(table.Has(key))
}