Documentation
¶
Overview ¶
This is an implementation of the k8s util sets package using Go 1.18 generics.
It implements the same API as k8s.io/apimachinery/pkg/util/sets
Instead of creating a sets.StringSet you can use sets.New[string]() and the same functionality is available.
Index ¶
- type Set
- func (s Set[T]) Delete(items ...T) Set[T]
- func (s Set[T]) Difference(s2 Set[T]) Set[T]
- func (s Set[T]) Equal(s2 Set[T]) bool
- func (s Set[T]) Has(item T) bool
- func (s Set[T]) HasAll(items ...T) bool
- func (s Set[T]) HasAny(items ...T) bool
- func (s Set[T]) Insert(items ...T) Set[T]
- func (s Set[T]) Intersection(s2 Set[T]) Set[T]
- func (s Set[T]) IsSuperset(s2 Set[T]) bool
- func (s Set[T]) Len() int
- func (s Set[T]) List() []T
- func (s Set[T]) SortedList(sorter func(x, y T) bool) []T
- func (s1 Set[T]) Union(s2 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] map[T]empty
Set is a generic Set implementation with some basic Set methods.
func (Set[T]) Difference ¶
Difference returns a set of objects that are not in s2 For example: s1 = {a1, a2, a3} s2 = {a1, a2, a4, a5} s1.Difference(s2) = {a3} s2.Difference(s1) = {a4, a5}
func (Set[T]) Equal ¶
Equal returns true if s is equal (as a set) to s2.
Two sets are equal if their membership is identical.
func (Set[T]) Intersection ¶
Intersection returns a new set which includes the item in BOTH s and s2 For example: s = {a1, a2} s2 = {a2, a3} s.Intersection(s2) = {a2}
func (Set[T]) IsSuperset ¶
IsSuperset returns true if s is a superset of s2.
func (Set[T]) List ¶
func (s Set[T]) List() []T
List returns a slice with all the items.
These items are not sorted.
func (Set[T]) SortedList ¶
SortedList returns a slice with all the items sorted using the sort function.
The sort func is passed through to sort.Slice.