-
Notifications
You must be signed in to change notification settings - Fork 3
/
set.go
37 lines (32 loc) · 852 Bytes
/
set.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package setKit
import (
mapset "github.com/deckarep/golang-set/v2"
)
// NewSet
/*
@param threadSafe 是否并发安全?
e.g.
set := setKit.NewSet[interface{}](false)
// Add成功
fmt.Println(set.Add(1)) // true
// Add失败
fmt.Println(set.Add(1)) // false
*/
func NewSet[T comparable](threadSafe bool, args ...T) mapset.Set[T] {
if threadSafe {
return mapset.NewSet(args...)
}
return mapset.NewThreadUnsafeSet(args...)
}
func NewSetFromMapKeys[T comparable, V any](threadSafe bool, val map[T]V) mapset.Set[T] {
if threadSafe {
return mapset.NewSetFromMapKeys(val)
}
return mapset.NewThreadUnsafeSetFromMapKeys(val)
}
func NewSetWithSize[T comparable](threadSafe bool, cardinality int) mapset.Set[T] {
if threadSafe {
return mapset.NewSetWithSize[T](cardinality)
}
return mapset.NewThreadUnsafeSetWithSize[T](cardinality)
}