Merge remote-tracking branch 'origin' into refactor/name-bucket-slot-table
All checks were successful
CI / Check PR Title (pull_request) Successful in 30s
CI / Go Lint (pull_request) Successful in 48s
CI / Markdown Lint (pull_request) Successful in 34s
CI / Makefile Lint (pull_request) Successful in 49s
CI / Unit Tests (pull_request) Successful in 48s
CI / Fuzz Tests (pull_request) Successful in 1m17s
CI / Mutation Tests (pull_request) Successful in 1m23s

This commit is contained in:
2026-04-15 23:13:41 -04:00
4 changed files with 28 additions and 21 deletions

View File

@@ -95,24 +95,31 @@ func (t *Table[K, V]) shrink() error {
return t.resize(t.tableA.capacity / t.growthFactor)
}
// Get fetches the value for a key in the [Table]. Returns an error if no value
// is found.
func (t *Table[K, V]) Get(key K) (value V, err error) {
// 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.tableA.get(key); ok {
return item, nil
return item, true
}
if item, ok := t.tableB.get(key); ok {
return item, nil
return item, true
}
return value, fmt.Errorf("key '%v' not found", key)
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) {
_, err := t.Get(key)
return err == nil
func (t Table[K, V]) Has(key K) (exists bool) {
_, exists = t.Get(key)
return
}
// Put sets the value for a key. Returns error if its value cannot be set.