Documentation
¶
Overview ¶
Package set provides a generic set implementation
Index ¶
- func AddMapKeys[K comparable, V any](dst Set[K], src map[K]V)
- func AddMapValues[K comparable, V comparable](dst Set[V], src map[K]V)
- type Set
- func Difference[T comparable](a, b Set[T]) Set[T]
- func Intersection[T comparable](a, b Set[T]) Set[T]
- func Make[T comparable](capacity ...int) Set[T]
- func Of[T comparable](vs ...T) Set[T]
- func OfSeq[T comparable](s iter.Seq[T]) Set[T]
- func OfSlice[T comparable](vs []T) Set[T]
- func Union[T comparable](a, b Set[T]) Set[T]
- func (s Set[T]) Add(v T)
- func (s Set[T]) AddSet(vs Set[T])
- func (s Set[T]) AddSlice(vs []T)
- func (s Set[T]) Clear()
- func (s Set[T]) Contains(v T) bool
- func (s Set[T]) ContainsSlice(vs []T) bool
- func (s Set[T]) Empty() bool
- func (s Set[T]) Items() []T
- func (s Set[T]) MarshalJSON() ([]byte, error)
- func (s Set[T]) Remove(v T)
- func (s Set[T]) RemoveSet(vs Set[T])
- func (s Set[T]) RemoveSlice(vs []T)
- func (s Set[T]) Size() int
- func (s *Set[T]) UnmarshalJSON(b []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddMapKeys ¶ added in v0.6.0
func AddMapKeys[K comparable, V any](dst Set[K], src map[K]V)
func AddMapValues ¶ added in v0.6.0
func AddMapValues[K comparable, V comparable](dst Set[V], src map[K]V)
Types ¶
type Set ¶
type Set[T comparable] map[T]struct{}
Set implements a set - an unordered collection of items wherein each item is unique.
The underlying storage mechanism is a map of set items to struct{}. To create a set, use make():
set := make(Set[int])
func Difference ¶
func Difference[T comparable](a, b Set[T]) Set[T]
Difference returns a new set representing the difference of sets a and b; that is, those items which are members of set a but not of set b.
func Intersection ¶
func Intersection[T comparable](a, b Set[T]) Set[T]
Intersection returns a new set representing the intersection of sets a and b; that is, those items which are members of both set a and set b.
func Make ¶ added in v0.4.0
func Make[T comparable](capacity ...int) Set[T]
Make returns an empty set of T
func OfSeq ¶ added in v0.8.0
func OfSeq[T comparable](s iter.Seq[T]) Set[T]
OfSeq returns a set comprising all items in the specified sequence.
func OfSlice ¶ added in v0.5.0
func OfSlice[T comparable](vs []T) Set[T]
OfSlice returns a set comprising all items in the specified slice.
func Union ¶
func Union[T comparable](a, b Set[T]) Set[T]
Union returns a new set representing the union of sets a and b; that is, those items which are members of either set a or set b.
func (Set[T]) AddSlice ¶
func (s Set[T]) AddSlice(vs []T)
AddSlice adds all elements of vs to the set.
func (Set[T]) ContainsSlice ¶
ContainsSlice returns true is the set contains all elements of vs, false otherwise.
func (Set[T]) MarshalJSON ¶ added in v0.3.0
func (Set[T]) RemoveSlice ¶
func (s Set[T]) RemoveSlice(vs []T)
RemoveSlice removes all elements of vs from the set.