From ac05eff1e845447126f36b53fe6043632828764f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Thu, 22 Dec 2022 10:23:34 +0100 Subject: [PATCH] v0.0.43 --- dataext/syncSet.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/dataext/syncSet.go b/dataext/syncSet.go index 3e625b6..fae5c82 100644 --- a/dataext/syncSet.go +++ b/dataext/syncSet.go @@ -2,17 +2,17 @@ package dataext import "sync" -type SyncStringSet struct { - data map[string]bool +type SyncSet[TData comparable] struct { + data map[TData]bool lock sync.Mutex } -func (s *SyncStringSet) Add(value string) bool { +func (s *SyncSet[TData]) Add(value TData) bool { s.lock.Lock() defer s.lock.Unlock() if s.data == nil { - s.data = make(map[string]bool) + s.data = make(map[TData]bool) } _, ok := s.data[value] @@ -21,12 +21,12 @@ func (s *SyncStringSet) Add(value string) bool { return !ok } -func (s *SyncStringSet) AddAll(values []string) { +func (s *SyncSet[TData]) AddAll(values []TData) { s.lock.Lock() defer s.lock.Unlock() if s.data == nil { - s.data = make(map[string]bool) + s.data = make(map[TData]bool) } for _, value := range values { @@ -34,12 +34,12 @@ func (s *SyncStringSet) AddAll(values []string) { } } -func (s *SyncStringSet) Contains(value string) bool { +func (s *SyncSet[TData]) Contains(value TData) bool { s.lock.Lock() defer s.lock.Unlock() if s.data == nil { - s.data = make(map[string]bool) + s.data = make(map[TData]bool) } _, ok := s.data[value] @@ -47,15 +47,15 @@ func (s *SyncStringSet) Contains(value string) bool { return ok } -func (s *SyncStringSet) Get() []string { +func (s *SyncSet[TData]) Get() []TData { s.lock.Lock() defer s.lock.Unlock() if s.data == nil { - s.data = make(map[string]bool) + s.data = make(map[TData]bool) } - r := make([]string, 0, len(s.data)) + r := make([]TData, 0, len(s.data)) for k := range s.data { r = append(r, k)