feat: add drop key functionality #6

Merged
mvhutz merged 12 commits from feat/drop-item into main 2026-03-20 01:59:55 +00:00
2 changed files with 20 additions and 4 deletions
Showing only changes of commit d4acdda95b - Show all commits

View File

@@ -26,6 +26,17 @@ func (b bucket[K, V]) get(key K) (value V, found bool) {
return slot.value, slot.occupied && b.compare(slot.key, key) return slot.value, slot.occupied && b.compare(slot.key, key)
} }
func (b bucket[K, V]) drop(key K) (occupied bool) {
slot := &b.slots[b.location(key)]
if slot.occupied && b.compare(slot.key, key) {
slot.occupied = false
return true
}
return false
}
func (b *bucket[K, V]) resize(capacity uint64) { func (b *bucket[K, V]) resize(capacity uint64) {
b.slots = make([]slot[K, V], capacity) b.slots = make([]slot[K, V], capacity)
b.capacity = capacity b.capacity = capacity

View File

@@ -111,10 +111,15 @@ func (t *Table[K, V]) Put(key K, value V) (err error) {
// Drop removes a value for a key in the table. Returns an error if its value // Drop removes a value for a key in the table. Returns an error if its value
// cannot be removed. // cannot be removed.
// func (t Table[K, V]) Drop(key K) (err error) {
// Deprecated: Do not use. t.bucketA.drop(key)
func (t Table[K, V]) Drop(_ K) { t.bucketB.drop(key)
panic("Not implemented")
if t.load() < t.minLoadFactor {
return t.resize()
}
return nil
} }
// Entries returns an unordered sequence of all key-value pairs in the table. // Entries returns an unordered sequence of all key-value pairs in the table.