From d4acdda95b61c20fd2541b9d038ac107f63f770d Mon Sep 17 00:00:00 2001 From: "M.V. Hutz" Date: Thu, 19 Mar 2026 19:54:16 -0400 Subject: [PATCH] feat: implement drop functionality - Added `drop()` function in buckets. - Implemented `Drop()` function for Table. --- bucket.go | 11 +++++++++++ table.go | 13 +++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/bucket.go b/bucket.go index 63a6681..9bf30a2 100644 --- a/bucket.go +++ b/bucket.go @@ -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) } +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) { b.slots = make([]slot[K, V], capacity) b.capacity = capacity diff --git a/table.go b/table.go index 78ef2ae..bc56a17 100644 --- a/table.go +++ b/table.go @@ -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 // cannot be removed. -// -// Deprecated: Do not use. -func (t Table[K, V]) Drop(_ K) { - panic("Not implemented") +func (t Table[K, V]) Drop(key K) (err error) { + t.bucketA.drop(key) + t.bucketB.drop(key) + + if t.load() < t.minLoadFactor { + return t.resize() + } + + return nil } // Entries returns an unordered sequence of all key-value pairs in the table.