From 90c974c7ea942a9e3842457ad614588171061ab8 Mon Sep 17 00:00:00 2001 From: HotPotatoC Date: Fri, 24 Dec 2021 00:13:00 +0700 Subject: [PATCH] feat(map): add instant delete if '*' is provided --- datastructure/map.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/datastructure/map.go b/datastructure/map.go index 00cdf98..41b4628 100644 --- a/datastructure/map.go +++ b/datastructure/map.go @@ -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