Documentation
¶
Overview ¶
Package set defines a Set type that holds a set of elements.
Index ¶
- type Set
- func (s *Set[E]) Add(v ...E)
- func (s *Set[E]) AddSet(s2 *Set[E])
- func (s *Set[E]) All() iter.Seq[E]
- func (s *Set[E]) Clear()
- func (s *Set[E]) Clone() *Set[E]
- func (s *Set[E]) Contains(v E) bool
- func (s *Set[E]) ContainsAll(s2 *Set[E]) bool
- func (s *Set[E]) ContainsAny(s2 *Set[E]) bool
- func (s *Set[E]) Equal(s2 *Set[E]) bool
- func (s *Set[E]) GoString() string
- func (s *Set[E]) Len() int
- func (s *Set[E]) Remove(v ...E)
- func (s *Set[E]) RemoveIf(remove func(E) bool)
- func (s *Set[E]) RemoveSet(s2 *Set[E])
- func (s *Set[E]) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set[E comparable] struct { // contains filtered or unexported fields }
A Set is a set of elements of some comparable type. Sets are implemented using maps, and have similar performance characteristics. Like maps, Sets are reference types. That is, for Sets s1 = s2 will leave s1 and s2 pointing to the same set of elements: changes to s1 will be reflected in s2 and vice versa. Unlike maps, the zero value of a Set is usable; there is no equivalent to make. As with maps, concurrent calls to functions and methods that read values are fine; concurrent calls to functions and methods that write values are racy.
func Difference ¶
func Difference[E comparable](s1, s2 *Set[E]) *Set[E]
Difference constructs a new set containing the elements of s1 that are not present in s2.
func Intersection ¶
func Intersection[E comparable](s1, s2 *Set[E]) *Set[E]
Intersection constructs a new set containing the intersection of s1 and s2.
func Of ¶
func Of[E comparable](v ...E) *Set[E]
Of returns a new set containing the listed elements.
func Union ¶
func Union[E comparable](s1, s2 *Set[E]) *Set[E]
Union constructs a new set containing the union of s1 and s2.
func (*Set[E]) All ¶ added in v0.0.2
All returns an iterator over the elements in the set. The iteration order is not specified and is not guaranteed to be the same from one call to the next.
func (*Set[E]) Clear ¶
func (s *Set[E]) Clear()
Clear removes all elements from s, leaving it empty.
func (*Set[E]) Clone ¶
Clone returns a copy of s. The elements are copied using assignment, so this is a shallow clone.
func (*Set[E]) ContainsAll ¶
ContainsAll reports whether all of the elements in s2 are in s.
func (*Set[E]) ContainsAny ¶
ContainsAny reports whether any of the elements in s2 are in s.
func (*Set[E]) Remove ¶
func (s *Set[E]) Remove(v ...E)
Remove removes elements from a set. Elements that are not present are ignored.