fix: public facing key/value fields in entry
All checks were successful
CI / Check PR Title (pull_request) Successful in 19s
CI / Go Lint (pull_request) Successful in 42s
CI / Markdown Lint (pull_request) Successful in 23s
CI / Makefile Lint (pull_request) Successful in 41s
CI / Unit Tests (pull_request) Successful in 41s
CI / Fuzz Tests (pull_request) Successful in 1m12s
CI / Mutation Tests (pull_request) Successful in 58s

This commit is contained in:
2026-04-04 00:38:27 +02:00
parent afead3330a
commit ca66ccd040
2 changed files with 13 additions and 13 deletions

View File

@@ -2,8 +2,8 @@ package cuckoo
// An Entry is a key-value pair. // An Entry is a key-value pair.
type Entry[K, V any] struct { type Entry[K, V any] struct {
key K Key K
value V Value V
} }
type slot[K, V any] struct { type slot[K, V any] struct {
@@ -30,7 +30,7 @@ func (b bucket[K, V]) get(key K) (value V, found bool) {
} }
slot := b.slots[b.location(key)] slot := b.slots[b.location(key)]
return slot.value, slot.occupied && b.compare(slot.key, key) return slot.Value, slot.occupied && b.compare(slot.Key, key)
} }
func (b *bucket[K, V]) drop(key K) (occupied bool) { func (b *bucket[K, V]) drop(key K) (occupied bool) {
@@ -40,7 +40,7 @@ func (b *bucket[K, V]) drop(key K) (occupied bool) {
slot := &b.slots[b.location(key)] slot := &b.slots[b.location(key)]
if slot.occupied && b.compare(slot.key, key) { if slot.occupied && b.compare(slot.Key, key) {
slot.occupied = false slot.occupied = false
b.size-- b.size--
return true return true
@@ -65,8 +65,8 @@ func (b bucket[K, V]) update(key K, value V) (updated bool) {
slot := &b.slots[b.location(key)] slot := &b.slots[b.location(key)]
if slot.occupied && b.compare(slot.key, key) { if slot.occupied && b.compare(slot.Key, key) {
slot.value = value slot.Value = value
return true return true
} }
@@ -78,7 +78,7 @@ func (b *bucket[K, V]) insert(insertion Entry[K, V]) (evicted Entry[K, V], evict
return insertion, true return insertion, true
} }
slot := &b.slots[b.location(insertion.key)] slot := &b.slots[b.location(insertion.Key)]
if !slot.occupied { if !slot.occupied {
slot.Entry = insertion slot.Entry = insertion
@@ -87,8 +87,8 @@ func (b *bucket[K, V]) insert(insertion Entry[K, V]) (evicted Entry[K, V], evict
return return
} }
if b.compare(slot.key, insertion.key) { if b.compare(slot.Key, insertion.Key) {
slot.value = insertion.value slot.Value = insertion.Value
return return
} }

View File

@@ -49,11 +49,11 @@ func (t Table[K, V]) load() float64 {
// size of the table. Returns a displaced entry and 'homeless = true' if an // size of the table. Returns a displaced entry and 'homeless = true' if an
// entry could not be placed after exhausting evictions. // entry could not be placed after exhausting evictions.
func (t *Table[K, V]) insert(entry Entry[K, V]) (displaced Entry[K, V], homeless bool) { func (t *Table[K, V]) insert(entry Entry[K, V]) (displaced Entry[K, V], homeless bool) {
if t.bucketA.update(entry.key, entry.value) { if t.bucketA.update(entry.Key, entry.Value) {
return return
} }
if t.bucketB.update(entry.key, entry.value) { if t.bucketB.update(entry.Key, entry.Value) {
return return
} }
@@ -190,7 +190,7 @@ func (t Table[K, V]) Entries() iter.Seq2[K, V] {
return func(yield func(K, V) bool) { return func(yield func(K, V) bool) {
for _, slot := range t.bucketA.slots { for _, slot := range t.bucketA.slots {
if slot.occupied { if slot.occupied {
if !yield(slot.key, slot.value) { if !yield(slot.Key, slot.Value) {
return return
} }
} }
@@ -198,7 +198,7 @@ func (t Table[K, V]) Entries() iter.Seq2[K, V] {
for _, slot := range t.bucketB.slots { for _, slot := range t.bucketB.slots {
if slot.occupied { if slot.occupied {
if !yield(slot.key, slot.value) { if !yield(slot.Key, slot.Value) {
return return
} }
} }