Documentation
¶
Index ¶
- type Set
- func (s Set[E]) Add(e ...E) Set[E]
- func (s Set[E]) Clone() Set[E]
- func (s Set[E]) Delete(e E) bool
- func (s Set[E]) Difference(other Set[E]) Set[E]
- func (s Set[E]) Equal(other Set[E]) bool
- func (s Set[E]) Has(e E) bool
- func (s Set[E]) Intersection(other Set[E]) Set[E]
- func (s Set[E]) Slice() []E
- func (s Set[E]) String() string
- func (s Set[E]) Subset(other Set[E]) bool
- func (s Set[E]) Subtract(e ...E) Set[E]
- func (s Set[E]) Superset(other Set[E]) bool
- func (s Set[E]) Union(other Set[E]) Set[E]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set[E comparable] map[E]empty
Set is a set of comparable elements of type E. Note since Set is backed by a map, the zero value of Set is not an empty set. Use New[E]() to create an empty set.
Set is not thread-safe.
func FromMap ¶
func FromMap[E comparable, T any, M ~map[E]T](m M) Set[E]
FromMap returns a new Unordered set containing the keys of the given map.
func New ¶
func New[E comparable](elements ...E) Set[E]
New returns a new set containing the given elements.
func (Set[E]) Delete ¶
Delete the given element from s. Returns true if the element was in s. If you need to remove multiple elements at once, use Subtract.
func (Set[E]) Difference ¶
Difference returns a new set containing the elements in s that are not in other.
s := New[int](1, 2, 3) other := New[int](3, 4, 5) sMinusOther := s.Difference(other) // contains 1, 2 otherMinusS := other.Difference(s) // contains 4, 5
func (Set[E]) Intersection ¶
Intersection returns a new set containing the elements in both s and other.
s := New[int](1, 2, 3) other := New[int](3, 4, 5) intersection := s.Intersection(other) // intersection contains 3
func (Set[E]) Slice ¶
func (s Set[E]) Slice() []E
Slice returns a slice of all the elements in s.
Note: The order of the output elements is undefined.
func (Set[E]) Subtract ¶ added in v0.2.0
Subtract removes multipe elements from s and returns itself