fix: allow 0 capacity for table

- Added guards at the bucket level, to ensure that getting an item in an empty bucket doesn't cause an error.
- Added grow() and shrink() functions to Table, to prevent a capacity of 0 from not being able to grow.
- Updated the fuzz test to use `go_fuzz-utils`.
This commit is contained in:
2026-03-19 20:46:31 -04:00
parent bb874a2aba
commit cdb5efb4a3
7 changed files with 81 additions and 32 deletions

View File

@@ -22,11 +22,19 @@ func (b bucket[K, V]) location(key K) uint64 {
}
func (b bucket[K, V]) get(key K) (value V, found bool) {
if b.capacity == 0 {
return
}
slot := b.slots[b.location(key)]
return slot.value, slot.occupied && b.compare(slot.key, key)
}
func (b *bucket[K, V]) drop(key K) (occupied bool) {
if b.capacity == 0 {
return
}
slot := &b.slots[b.location(key)]
if slot.occupied && b.compare(slot.key, key) {
@@ -45,6 +53,10 @@ func (b *bucket[K, V]) resize(capacity uint64) {
}
func (b bucket[K, V]) update(key K, value V) (updated bool) {
if b.capacity == 0 {
return
}
slot := &b.slots[b.location(key)]
if slot.occupied && b.compare(slot.key, key) {
@@ -56,6 +68,10 @@ func (b bucket[K, V]) update(key K, value V) (updated bool) {
}
func (b *bucket[K, V]) evict(insertion entry[K, V]) (evicted entry[K, V], eviction bool) {
if b.capacity == 0 {
return insertion, true
}
slot := &b.slots[b.location(insertion.key)]
if !slot.occupied {