diff --git a/subtable.go b/subtable.go index f502bcf..53a9785 100644 --- a/subtable.go +++ b/subtable.go @@ -20,52 +20,52 @@ type subtable[K, V any] struct { // location determines where in the bucket a certain key would be placed. If the // capacity is 0, this will panic. -func (b *subtable[K, V]) location(key K) uint64 { - return b.hash(key) % b.capacity +func (t *subtable[K, V]) location(key K) uint64 { + return t.hash(key) % t.capacity } -func (b *subtable[K, V]) get(key K) (value V, found bool) { - if b.capacity == 0 { +func (t *subtable[K, V]) get(key K) (value V, found bool) { + if t.capacity == 0 { return } - slot := b.slots[b.location(key)] - return slot.Value, slot.occupied && b.compare(slot.Key, key) + slot := t.slots[t.location(key)] + return slot.Value, slot.occupied && t.compare(slot.Key, key) } -func (b *subtable[K, V]) drop(key K) (occupied bool) { - if b.capacity == 0 { +func (t *subtable[K, V]) drop(key K) (occupied bool) { + if t.capacity == 0 { return } - slot := &b.slots[b.location(key)] + slot := &t.slots[t.location(key)] - if slot.occupied && b.compare(slot.Key, key) { + if slot.occupied && t.compare(slot.Key, key) { slot.occupied = false - b.size-- + t.size-- return true } return false } -func (b *subtable[K, V]) resized(capacity uint64) *subtable[K, V] { +func (t *subtable[K, V]) resized(capacity uint64) *subtable[K, V] { return &subtable[K, V]{ slots: make([]slot[K, V], capacity), capacity: capacity, - hash: b.hash, - compare: b.compare, + hash: t.hash, + compare: t.compare, } } -func (b *subtable[K, V]) update(key K, value V) (updated bool) { - if b.capacity == 0 { +func (t *subtable[K, V]) update(key K, value V) (updated bool) { + if t.capacity == 0 { return } - slot := &b.slots[b.location(key)] + slot := &t.slots[t.location(key)] - if slot.occupied && b.compare(slot.Key, key) { + if slot.occupied && t.compare(slot.Key, key) { slot.Value = value return true } @@ -73,21 +73,21 @@ func (b *subtable[K, V]) update(key K, value V) (updated bool) { return false } -func (b *subtable[K, V]) insert(insertion Entry[K, V]) (evicted Entry[K, V], eviction bool) { - if b.capacity == 0 { +func (t *subtable[K, V]) insert(insertion Entry[K, V]) (evicted Entry[K, V], eviction bool) { + if t.capacity == 0 { return insertion, true } - slot := &b.slots[b.location(insertion.Key)] + slot := &t.slots[t.location(insertion.Key)] if !slot.occupied { slot.Entry = insertion slot.occupied = true - b.size++ + t.size++ return } - if b.compare(slot.Key, insertion.Key) { + if t.compare(slot.Key, insertion.Key) { slot.Value = insertion.Value return }