From 0c81bc5cae71fd71a07ddf441a78e863173a3ba1 Mon Sep 17 00:00:00 2001 From: "M.V. Hutz" Date: Thu, 19 Mar 2026 21:06:12 -0400 Subject: [PATCH] docs: added comments to give context to functions --- bucket.go | 2 ++ table.go | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/bucket.go b/bucket.go index 15dd2d7..6a4171c 100644 --- a/bucket.go +++ b/bucket.go @@ -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 } diff --git a/table.go b/table.go index 9b64def..3e2a1a6 100644 --- a/table.go +++ b/table.go @@ -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) }