docs: added comments to give context to functions
Some checks failed
CI / Makefile Lint (pull_request) Successful in 21s
CI / Go Lint (pull_request) Failing after 12s
CI / Unit Tests (pull_request) Successful in 14s
CI / Fuzz Tests (pull_request) Successful in 1m14s
CI / Mutation Tests (pull_request) Successful in 53s

This commit is contained in:
2026-03-19 21:06:12 -04:00
parent bd3f0aad04
commit 0c81bc5cae
2 changed files with 9 additions and 0 deletions

View File

@@ -17,6 +17,8 @@ type bucket[K, V any] struct {
compare EqualFunc[K]
}
// location determines where in the bucket a certain key would be placed. If the
// capacity is 0, this will panic.
func (b bucket[K, V]) location(key K) uint64 {
return b.hash(key) % b.capacity
}

View File

@@ -45,6 +45,9 @@ func (t Table[K, V]) load() float64 {
return float64(t.Size()) / float64(t.TotalCapacity())
}
// resize clears all buckets, changes the sizes of them to a specific capacity,
// and fills them back up again. It is a helper function for [Table.grow] and
// [Table.shrink]; use them instead.
func (t *Table[K, V]) resize(capacity uint64) error {
entries := make([]entry[K, V], 0, t.Size())
for k, v := range t.Entries() {
@@ -63,6 +66,8 @@ func (t *Table[K, V]) resize(capacity uint64) error {
return nil
}
// grow increases the table's capacity by the [Table.growthFactor]. If the
// capacity is 0, it increases it to 1.
func (t *Table[K, V]) grow() error {
var newCapacity uint64
@@ -75,6 +80,8 @@ func (t *Table[K, V]) grow() error {
return t.resize(newCapacity)
}
// shrink reduces the table's capacity by the [Table.growthFactor]. It may
// reduce it down to 0.
func (t *Table[K, V]) shrink() error {
return t.resize(t.bucketA.capacity / t.growthFactor)
}