Documentation
¶
Overview ¶
Package set is a tiny generics based implementation for a set.
Index ¶
- type Set
- func (s Set[T]) Add(values ...T) Set[T]
- func (s Set[T]) Clone() Set[T]
- func (s Set[T]) Difference(other Set[T]) Set[T]
- func (s Set[T]) Exists(value T) bool
- func (s Set[T]) Intersection(other Set[T]) Set[T]
- func (s Set[T]) Iterate(f func(T) bool)
- func (s Set[T]) IterateSorted(f func(T) bool)
- func (s Set[T]) Remove(values ...T) Set[T]
- func (s Set[T]) Union(other Set[T]) Set[T]
- func (s Set[T]) Values() []T
- func (s Set[T]) ValuesSorted() []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
Set represents a generic set of unique values of the same type.
The values must be sortable.
func NewSet ¶
NewSet instantiates a new set.
If capacity is not empty, all values will be summed and used as the initial capacity of the set. The minimum initial capacity is forced to 8.
func (Set[T]) Difference ¶
Difference returns the difference of this and other set as a new set.
func (Set[T]) Intersection ¶
Intersection returns the intersection of this and other set as a new set.
func (Set[T]) Iterate ¶
Iterate calls the closure for all values in the set (in random order).
If the closure returns false, any remaining values will be skipped.
func (Set[T]) IterateSorted ¶
IterateSorted calls the closure for all sorted values in the set.
If the closure returns false, any remaining values will be skipped.
func (Set[T]) ValuesSorted ¶
func (s Set[T]) ValuesSorted() []T
ValuesSorted returns a sorted slice of the values.