Documentation
¶
Overview ¶
Package set implements a set of any comparable type.
A set is an unordered list of elements with no duplicates.
Index ¶
- type Set
- func (s Set[T]) Add(es ...T)
- func (s *Set[T]) Clear()
- func (s Set[T]) Contains(e T) bool
- func (s Set[T]) Difference(other Set[T]) Set[T]
- func (s Set[T]) ForEach(f func(e T))
- func (s Set[T]) Intersection(other Set[T]) Set[T]
- func (s Set[T]) IsDisjoint(other Set[T]) bool
- func (s Set[T]) IsEqual(other Set[T]) bool
- func (s Set[T]) IsProperSubset(other Set[T]) bool
- func (s Set[T]) IsProperSuperset(other Set[T]) bool
- func (s Set[T]) IsSubset(other Set[T]) bool
- func (s Set[T]) IsSuperset(other Set[T]) bool
- func (s Set[T]) Iter() <-chan T
- func (s Set[T]) Len() int
- func (s Set[T]) Pop() T
- func (s Set[T]) Remove(es ...T)
- func (s Set[T]) String() string
- func (s Set[T]) SymmetricDifference(other Set[T]) Set[T]
- func (s Set[T]) ToSlice() []T
- func (s Set[T]) Union(other Set[T]) Set[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set[T comparable] map[T]struct{}
Set represents an unordered list of elements.
func New ¶
func New[T comparable](es ...T) Set[T]
New create and returns an initialized Set, optionally with the given elements.
func NewFromSlice ¶
func NewFromSlice[T comparable](sl []T) Set[T]
NewFromSlice create and returns a new set from an existing slice.
func NewWithSize ¶
func NewWithSize[T comparable](size int) Set[T]
NewWithSize create and returns an initialized and empty set with a given size.
func (Set[T]) Add ¶
func (s Set[T]) Add(es ...T)
Add adds all the given elements to the set. If any element is already in the set, Add is a no-op for that element.
func (Set[T]) Difference ¶
Difference returns a new set with elements in s that are not in other.
func (Set[T]) ForEach ¶
func (s Set[T]) ForEach(f func(e T))
ForEach is used to iterate over every element of the set by calling a user-defined function with every element.
func (Set[T]) Intersection ¶
Intersection returns a new set with elements common to s and other.
func (Set[T]) IsDisjoint ¶
IsDisjoint returns true if s has no elements in common with other. Sets are disjoint if and only if their intersection is an empty set.
func (Set[T]) IsEqual ¶
IsEqual returns true if s is equal to other. Sets are equal if their lengths are equal and every element of s is in other.
func (Set[T]) IsProperSubset ¶
IsProperSubset returns true if s is a proper subset of other, that is, s is a subset of other and length of s is strictly less than other.
func (Set[T]) IsProperSuperset ¶
IsProperSuperset returns true if s is a proper superset of other, that is, s is a superset of other and length of s is strictly greater than other.
func (Set[T]) IsSuperset ¶
IsSuperset returns true if every element in other is in s, false otherwise.
func (Set[T]) Iter ¶
func (s Set[T]) Iter() <-chan T
Iter is used to iterate over every element of the set. It returns a receive-only buffered channel whose size is half of set length.
func (Set[T]) Pop ¶
func (s Set[T]) Pop() T
Pop removes and returns an arbitrary item from the set. If the set is empty, then it will return the zero value for the constrained type.
func (Set[T]) Remove ¶
func (s Set[T]) Remove(es ...T)
Remove deletes all the given elements from the set. If there is no such element, Remove is a no-op.
func (Set[T]) SymmetricDifference ¶
SymmetricDifference returns a new set with elements in either s or other but not in both.