1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 00:22:41 +08:00
This commit is contained in:
2024-05-28 04:25:17 +08:00
parent b4ac1cc449
commit 38f7cc75c9
2 changed files with 39 additions and 40 deletions

View File

@ -1,15 +1,13 @@
package sets
import (
"sync"
"github.com/charlienet/go-mixed/locker"
"golang.org/x/exp/constraints"
)
type Set[T comparable] interface {
Add(...T)
Remove(v T)
Add(...T) Set[T]
Remove(v T) Set[T]
Asc() Set[T]
Desc() Set[T]
Contains(T) bool
@ -19,18 +17,16 @@ type Set[T comparable] interface {
ToSlice() []T // 转换为切片
}
var defaultOptions = option{locker: locker.NewEmptyLocker()}
type option struct {
locker sync.Locker
locker locker.Locker
}
type setFunc func(option)
type setFunc func(*option)
func WithSync() setFunc {
return func(o option) {
o.locker = &sync.RWMutex{}
return func(o *option) {
o.locker.Synchronize()
}
}