feat!: Drop returns bool, Put doesn't stack-overflow (#21)
All checks were successful
CI / Check PR Title (push) Has been skipped
CI / Go Lint (push) Successful in 58s
CI / Makefile Lint (push) Successful in 55s
CI / Markdown Lint (push) Successful in 34s
CI / Unit Tests (push) Successful in 54s
CI / Fuzz Tests (push) Successful in 1m26s
CI / Mutation Tests (push) Successful in 1m11s

## Description

Closes #11.

## Changes

### Design Decisions

## Checklist

- [ ] Tests pass
- [ ] Docs updated

Reviewed-on: #21
Co-authored-by: M.V. Hutz <git@maximhutz.me>
Co-committed-by: M.V. Hutz <git@maximhutz.me>
This commit was merged in pull request #21.
This commit is contained in:
2026-04-17 01:31:01 +00:00
committed by Maxim Hutz
parent 29ba6bfd4d
commit 39548b4332
6 changed files with 107 additions and 65 deletions

View File

@@ -1,5 +1,6 @@
package cuckoo
// An entry is a key-value pair.
type entry[K, V any] struct {
key K
value V
@@ -48,10 +49,13 @@ func (t *subtable[K, V]) drop(key K) (occupied bool) {
return false
}
func (t *subtable[K, V]) resize(capacity uint64) {
t.slots = make([]slot[K, V], capacity)
t.capacity = capacity
t.size = 0
func (t *subtable[K, V]) resized(capacity uint64) *subtable[K, V] {
return &subtable[K, V]{
slots: make([]slot[K, V], capacity),
capacity: capacity,
hash: t.hash,
compare: t.compare,
}
}
func (t *subtable[K, V]) update(key K, value V) (updated bool) {
@@ -69,7 +73,7 @@ func (t *subtable[K, V]) update(key K, value V) (updated bool) {
return false
}
func (t *subtable[K, V]) evict(insertion entry[K, V]) (evicted entry[K, V], eviction bool) {
func (t *subtable[K, V]) insert(insertion entry[K, V]) (evicted entry[K, V], eviction bool) {
if t.capacity == 0 {
return insertion, true
}
@@ -92,8 +96,8 @@ func (t *subtable[K, V]) evict(insertion entry[K, V]) (evicted entry[K, V], evic
return insertion, true
}
func newSubtable[K, V any](capacity uint64, hash Hash[K], compare EqualFunc[K]) subtable[K, V] {
return subtable[K, V]{
func newSubtable[K, V any](capacity uint64, hash Hash[K], compare EqualFunc[K]) *subtable[K, V] {
return &subtable[K, V]{
hash: hash,
capacity: capacity,
compare: compare,