diff --git a/pkg/hashset/hashset.go b/pkg/hashset/hashset.go index e52a05e..b39e55b 100644 --- a/pkg/hashset/hashset.go +++ b/pkg/hashset/hashset.go @@ -33,3 +33,7 @@ func (h *HashSet[K]) Size() int { func (h *HashSet[K]) Clear() { maps.Clear(h.m) } + +func (h *HashSet[K]) Keys() []K { + return maps.Keys(h.m) +} diff --git a/pkg/hashset/hashset_sync.go b/pkg/hashset/hashset_sync.go index 374deae..cef5e65 100644 --- a/pkg/hashset/hashset_sync.go +++ b/pkg/hashset/hashset_sync.go @@ -1,6 +1,8 @@ package hashset -import "sync" +import ( + "sync" +) type SyncHashSet[K comparable] struct { rw sync.RWMutex @@ -60,3 +62,10 @@ func (sh *SyncHashSet[K]) Clear() { sh.s.Clear() } + +func (sh *SyncHashSet[K]) Keys() []K { + sh.rw.RLock() + defer sh.rw.RUnlock() + + return sh.s.Keys() +}