Skip to content

Commit

Permalink
feat(map): add instant delete if '*' is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
HotPotatoC committed Dec 23, 2021
1 parent 2fcbfc0 commit 90c974c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions datastructure/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ func (m *Map) Delete(k string) int64 {
func (m *Map) delete(k string) int64 {
deletedN := int64(0)

// Delete all keys if '*' pattern is provided
if k == "*" {
m.items.Range(func(key, value interface{}) bool {
m.items.Delete(key)
deletedN++
return true
})

return deletedN
}

_, loaded := m.items.LoadAndDelete(k)
if !loaded {
// If the given key was not loaded, attempt to check
Expand Down

0 comments on commit 90c974c

Please sign in to comment.