Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set[V comparable] map[V]struct{}
Set 基于map的Set.
func NewSet ¶
func NewSet[V comparable](elems ...V) Set[V]
NewSet 新建MapSet.
Example ¶
ExampleNewSet is an example function.
package main
import (
"fmt"
"sort"
"github.com/xuender/kit/set"
)
func main() {
nums := set.NewSet(1, 2, 3)
fmt.Println(len(nums))
fmt.Println(len(nums.Add(3, 4, 5)))
fmt.Println(nums.Has(0))
fmt.Println(nums.Has(3))
delete(nums, 2)
ints := nums.Slice()
sort.Ints(ints)
fmt.Println(ints)
}
Output: 3 5 false true [1 3 4 5]
type Sync ¶
type Sync[V comparable] struct { // contains filtered or unexported fields }
Sync 线程安全Set.
func NewSync ¶
func NewSync[V comparable](elems ...V) *Sync[V]
NewSync 新建线程安全Set.
Example ¶
ExampleNewSync is an example function.
package main
import (
"fmt"
"sort"
"github.com/xuender/kit/set"
)
func main() {
nums := set.NewSync(1, 2, 3)
fmt.Println(nums.Len())
fmt.Println(nums.Add(3, 4, 5).Len())
fmt.Println(nums.Has(0))
fmt.Println(nums.Has(3))
nums.Delete(2)
ints := nums.Slice()
sort.Ints(ints)
fmt.Println(ints)
}
Output: 3 5 false true [1 3 4 5]
Click to show internal directories.
Click to hide internal directories.