v0.0.43
This commit is contained in:
parent
1aaad66233
commit
ac05eff1e8
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user