feat: Table.Find
All checks were successful
CI / Check PR Title (pull_request) Successful in 29s
CI / Go Lint (pull_request) Successful in 42s
CI / Markdown Lint (pull_request) Successful in 31s
CI / Makefile Lint (pull_request) Successful in 40s
CI / Unit Tests (pull_request) Successful in 39s
CI / Fuzz Tests (pull_request) Successful in 1m40s
CI / Mutation Tests (pull_request) Successful in 1m23s

This commit is contained in:
2026-04-13 21:54:29 -04:00
parent 572e59f33d
commit 81ce24e7b7

View File

@@ -95,7 +95,8 @@ func (t *Table[K, V]) shrink() error {
return t.resize(t.bucketA.capacity / t.growthFactor)
}
// Get fetches the value for a key in the [Table].
// Get fetches the value for a key in the [Table]. Matches the comma-ok pattern
// of a builtin map; see [Table.Find] for plain indexing.
func (t Table[K, V]) Get(key K) (value V, ok bool) {
if item, ok := t.bucketA.get(key); ok {
return item, true
@@ -108,6 +109,13 @@ func (t Table[K, V]) Get(key K) (value V, ok bool) {
return
}
// Find fetches the value of a key. Matches direct indexing of a builtin map;
// see [Table.Get] for a comma-ok pattern.
func (t Table[K, V]) Find(key K) (value V) {
value, _ = t.Get(key)
return
}
// Has returns true if a key has a value in the table.
func (t Table[K, V]) Has(key K) (exists bool) {
_, exists = t.Get(key)