set

package
v0.0.0-...-e28bee9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2026 License: Apache-2.0 Imports: 4 Imported by: 46

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsSortedArray

func AsSortedArray[K cmp.Ordered](s Set[K]) []K

AsSortedArray returns the contents as a sorted K slice.

This is a separate function and not a method because not all types supported by Generic are ordered and only those can be sorted.

func Clone

func Clone[K comparable, S ~map[K]struct{}](set S) S

func Keys

func Keys[K comparable, V any](m map[K]V, cmp maputils.CompareFunc[K]) []K

Types

type Set

type Set[K comparable] map[K]struct{}

func KeySet

func KeySet[K comparable, V any](m map[K]V) Set[K]

func New

func New[K comparable](keys ...K) Set[K]

func (Set[K]) Add

func (s Set[K]) Add(keys ...K) Set[K]

func (Set[K]) AddAll

func (s Set[K]) AddAll(set Set[K]) Set[K]

func (Set[K]) AsArray

func (s Set[K]) AsArray() []K

func (Set[K]) Clear

func (s Set[K]) Clear() bool

func (Set[K]) Clone

func (s Set[K]) Clone() Set[K]

func (Set[K]) Contains

func (s Set[K]) Contains(keys ...K) bool

func (Set[K]) ContainsAll

func (s Set[K]) ContainsAll(items ...K) bool

func (Set[K]) ContainsAny

func (s Set[K]) ContainsAny(items ...K) bool

func (Set[K]) Delete

func (s Set[K]) Delete(keys ...K) Set[K]

func (Set[K]) DeleteAll

func (s Set[K]) DeleteAll(set Set[K]) Set[K]

func (Set[K]) Difference

func (s1 Set[K]) Difference(s2 Set[K]) Set[K]

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[K]) Elements

func (s Set[K]) Elements(yield func(e K) bool)

func (Set[K]) Equal

func (s1 Set[K]) Equal(s2 Set[K]) bool

Equal returns true if and only if s1 is equal (as a set) to s2. Both sets contain the same elements.

func (Set[K]) GetAny

func (s Set[K]) GetAny() (K, bool)

GetAny fetches a single element from the set and removes it.

func (Set[K]) Has

func (s Set[K]) Has(keys ...K) bool

func (Set[K]) HasAll

func (s Set[K]) HasAll(keys ...K) bool

func (Set[K]) HasAny

func (s Set[K]) HasAny(keys ...K) bool

func (Set[K]) Intersection

func (s1 Set[K]) Intersection(s2 Set[K]) Set[K]

Intersection returns a new set which includes the item in BOTH s1 and s2 For example: s1 = {a1, a2} s2 = {a2, a3} s1.Intersection(s2) = {a2}

func (Set[K]) IsEmpty

func (s Set[K]) IsEmpty() bool

func (Set[K]) IsSubset

func (s1 Set[K]) IsSubset(s2 Set[K]) bool

IsSubset returns true if and only if s1 is a subset of s2.

func (Set[K]) IsSuperset

func (s1 Set[K]) IsSuperset(s2 Set[K]) bool

IsSuperset returns true if and only if s1 is a superset of s2.

func (Set[K]) Len

func (s Set[K]) Len() int

func (Set[K]) SymmetricDifference

func (s1 Set[K]) SymmetricDifference(s2 Set[K]) Set[K]

SymmetricDifference returns a set of elements which are in either of the sets, but not in their intersection. For example: s1 = {a1, a2, a3} s2 = {a1, a2, a4, a5} s1.SymmetricDifference(s2) = {a3, a4, a5} s2.SymmetricDifference(s1) = {a3, a4, a5}

func (Set[K]) Union

func (s1 Set[K]) Union(s2 Set[K]) Set[K]

Union returns a new set which includes items in either s1 or s2. For example: s1 = {a1, a2} s2 = {a3, a4} s1.Union(s2) = {a1, a2, a3, a4} s2.Union(s1) = {a1, a2, a3, a4}

func (Set[K]) WithAdded

func (s Set[K]) WithAdded(elems ...K) Set[K]

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL