Documentation
¶
Index ¶
- type Iterator
- type Set
- func (s Set[T]) Add(val T) bool
- func (s Set[T]) Append(v ...T) int
- func (s Set[T]) Clear()
- func (s Set[T]) Clone() Set[T]
- func (s Set[T]) Collection() []T
- func (s Set[T]) Contains(v ...T) bool
- func (s Set[T]) ContainsAny(v ...T) bool
- func (s Set[T]) Difference(o Set[T]) Set[T]
- func (s Set[T]) Equal(o Set[T]) bool
- func (s Set[T]) Intersection(o Set[T]) Set[T]
- func (s Set[T]) Iterator() *Iterator[T]
- func (s Set[T]) Length() int
- func (s Set[T]) Remove(v T)
- func (s Set[T]) RemoveAll(i ...T)
- func (s Set[T]) Union(o Set[T]) Set[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Iterator ¶
type Iterator[T comparable] struct { // contains filtered or unexported fields }
Iterator defines an iterator over a Set, its channel can be used to range over the Set's elements.
type Set ¶
type Set[T comparable] map[T]struct{}
Set is used to handle use cases for the set data structure.
func (Set[T]) Append ¶
Append multiple elements to the set. It returns the number of elements added.
func (Set[T]) Clear ¶
func (s Set[T]) Clear()
Clear removes all elements from the set, leaving the empty set.
func (Set[T]) Clone ¶
Clone returns a clone of the set using the same implementation, duplicating all keys.
func (Set[T]) Collection ¶
func (s Set[T]) Collection() []T
Collection returns the elements of the set as a collection.
func (Set[T]) ContainsAny ¶
ContainsAny returns whether at least one of the given items are in the set.
func (Set[T]) Difference ¶
Difference returns the difference between this set and other. The returned set will contain all elements of this set that are not also elements of the second set.
Note that the argument to Difference must be of the same type as the receiver of the method. Otherwise, Difference will panic.
func (Set[T]) Equal ¶
Equal determines if two sets are equal to each other. If they have the same cardinality and contain the same elements, they are considered equal. The order in which the elements were added is irrelevant.
Note that the argument to Equal must be of the same type as the receiver of the method. Otherwise, Equal will panic.
func (Set[T]) Intersection ¶
Intersection returns a new set containing only the elements that exist only in both sets.
Note that the argument to Intersect must be of the same type as the receiver of the method. Otherwise, Intersect will panic.
func (Set[T]) Iterator ¶
Iterator returns an Iterator object that can be used to range over the set.