feat!: update get from (V, error) to (V, bool)
#20
10
table.go
10
table.go
@@ -95,7 +95,8 @@ func (t *Table[K, V]) shrink() error {
|
|||||||
return t.resize(t.bucketA.capacity / t.growthFactor)
|
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) {
|
func (t Table[K, V]) Get(key K) (value V, ok bool) {
|
||||||
if item, ok := t.bucketA.get(key); ok {
|
if item, ok := t.bucketA.get(key); ok {
|
||||||
return item, true
|
return item, true
|
||||||
@@ -108,6 +109,13 @@ func (t Table[K, V]) Get(key K) (value V, ok bool) {
|
|||||||
return
|
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.
|
// Has returns true if a key has a value in the table.
|
||||||
func (t Table[K, V]) Has(key K) (exists bool) {
|
func (t Table[K, V]) Has(key K) (exists bool) {
|
||||||
_, exists = t.Get(key)
|
_, exists = t.Get(key)
|
||||||
|
|||||||
Reference in New Issue
Block a user