Skip to content

Commit

Permalink
feat: ✨ hashset: keys (#80)
Browse files Browse the repository at this point in the history
Signed-off-by: thanhpp <thanhphanphu18@gmail.com>
  • Loading branch information
thanhpp authored Sep 4, 2024
1 parent 46ac751 commit 768171e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/hashset/hashset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
11 changes: 10 additions & 1 deletion pkg/hashset/hashset_sync.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package hashset

import "sync"
import (
"sync"
)

type SyncHashSet[K comparable] struct {
rw sync.RWMutex
Expand Down Expand Up @@ -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()
}

0 comments on commit 768171e

Please sign in to comment.