feat: drop item returns bool, whether item existed
This commit is contained in:
11
table.go
11
table.go
@@ -171,11 +171,10 @@ func (t *Table[K, V]) Put(key K, value V) (displaced Entry[K, V], err error) {
|
||||
return entry, fmt.Errorf("bad hash: could not place entry after %d resizes", defaultGrowthLimit)
|
||||
}
|
||||
|
||||
// Drop removes a value for a key in the table. Returns an error if its value
|
||||
// cannot be removed.
|
||||
func (t *Table[K, V]) Drop(key K) (err error) {
|
||||
t.bucketA.drop(key)
|
||||
t.bucketB.drop(key)
|
||||
// Drop removes a value for a key in the table. Returns whether the key had
|
||||
// existed.
|
||||
func (t *Table[K, V]) Drop(key K) bool {
|
||||
occupied := t.bucketA.drop(key) || t.bucketB.drop(key)
|
||||
|
||||
if t.load() < t.minLoadFactor {
|
||||
// The error is not handled here, because table-shrinking is an internal
|
||||
@@ -183,7 +182,7 @@ func (t *Table[K, V]) Drop(key K) (err error) {
|
||||
t.shrink()
|
||||
}
|
||||
|
||||
return nil
|
||||
return occupied
|
||||
}
|
||||
|
||||
// Entries returns an unordered sequence of all key-value pairs in the table.
|
||||
|
||||
Reference in New Issue
Block a user