Documentation
¶
Overview ¶
Example ¶
package main
import (
"fmt"
"github.com/bangumi/server/internal/pkg/generic/set"
)
func main() {
s := set.New[string]()
s.Add("foo")
s.Add("bar")
s.Add("baz")
fmt.Println(s.Has("foo"))
fmt.Println(s.Has("quux"))
}
Output: true false
Index ¶
- type Set
- func (s Set[T]) Add(item T)
- func (s Set[K]) Each(fn func(key K))
- func (s Set[T]) Has(item T) bool
- func (s Set[T]) Intersection(o Set[T]) Set[T]
- func (s Set[T]) Len() int
- func (s Set[T]) Remove(item T)
- func (s Set[T]) Removes(items ...T) Set[T]
- func (s Set[T]) ToSlice() []T
- func (s Set[T]) Union(o Set[T]) Set[T]
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
Set is a not thread-safe set based on built-in map.
func FromSlice ¶
func FromSlice[T comparable](in []T) Set[T]
func New ¶
func New[T comparable]() Set[T]
func (Set[T]) Intersection ¶
Intersection return a new set = (s1 & s2).
Click to show internal directories.
Click to hide internal directories.