Documentation
¶
Overview ¶
A set library for Go using generics
Package set provides a generic type-safe set library in Go, using the new generics language extension in Go 1.18 and higher.
Index ¶
- type Set
- func (s Set[T]) Add(e ...T)
- func (s Set[T]) All() iter.Seq[T]
- func (s Set[T]) Clear()
- func (s Set[T]) Contains(e ...T) bool
- func (s Set[T]) ContainsAny(e ...T) bool
- func (s Set[T]) Copy() Set[T]
- func (s Set[T]) Diff(t Set[T]) Set[T]
- func (s Set[T]) Intersect(t ...Set[T]) Set[T]
- func (s Set[T]) IsEmpty() bool
- func (s Set[T]) IsEqual(t Set[T]) bool
- func (s Set[T]) IsSubsetOf(t Set[T]) bool
- func (s Set[T]) IsSupersetOf(t Set[T]) bool
- func (s Set[T]) Iterator() (iterch <-chan T, donech chan<- struct{})deprecated
- func (s Set[T]) Len() int
- func (s Set[T]) List() []T
- func (s Set[T]) Remove(e ...T)
- func (s Set[T]) String() string
- func (s Set[T]) SymDiff(t Set[T]) Set[T]
- func (s Set[T]) Union(t ...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] struct { // contains filtered or unexported fields }
The Set is implemented as a map without values.
func New ¶
func New[T comparable](e ...T) Set[T]
New creates a new set and initializes it with the argument values. Note: NewInit() was renamed to New()
func (Set[T]) Contains ¶
Contains checks if a set contains one or more elements. The return value is true only if all given elements are in the set.
func (Set[T]) ContainsAny ¶
ContainsAny checks if a set contains one or more elements. The return value is true if at least one of the given elements is in the set.
func (Set[T]) Diff ¶
Diff returns a new set which represents the difference of two sets. The sets themselves are not modified.
func (Set[T]) Intersect ¶
Intersect returns a new set which represents the intersection of two or more sets. The sets themselves are not modified.
func (Set[T]) IsSubsetOf ¶
IsSubsetOf returns true if the set s is a subset of the set t, e.g. if all elements of s are also in t.
func (Set[T]) IsSupersetOf ¶
IsSupersetOf returns true if the set s is a superset of the set t, e.g. if all elements of t are also in s.
func (Set[T]) Iterator
deprecated
func (s Set[T]) Iterator() (iterch <-chan T, donech chan<- struct{})
Iterator returns a channel that can be used to iterate over the set. A second "done" channel can be used to preliminarily terminate the iteration by closing the done channel.
Deprecated: The Iterator method will be removed in a future release. Use the All() method to iterate over the set instead.
func (Set[T]) List ¶
func (s Set[T]) List() []T
List returns an unsorted list of the set elements in a slice.
func (Set[T]) Remove ¶
func (s Set[T]) Remove(e ...T)
Remove removes one or more elements from the given set.
func (Set[T]) String ¶
String returns a textual representation of the set in a string. It is there for implementing the fmt.Stringer interface to prettyprint the set.