set

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SortedSlice added in v0.6.4

func SortedSlice[E constraints.Ordered](set Set[E]) []E

SortedSlice takes a Set with constraints.Ordered items and returns a sorted slice of the items.

Types

type Empty

type Empty struct{}

Empty is the presence marker in a Set.

type Set

type Set[E comparable] map[E]Empty

Set is a set of unique values.

func New

func New[E comparable](items ...E) Set[E]

New creates a Set from a list of values.

func (Set[E]) Delete

func (s Set[E]) Delete(items ...E) Set[E]

Delete removes all items from the set.

func (Set[E]) Difference

func (s Set[E]) Difference(other Set[E]) Set[E]

Difference returns a set of objects that are not in other For example: s = {a1, a2, a3} other = {a1, a2, a4, a5} s.Difference(other) = {a3} other.Difference(s) = {a4, a5}

func (Set[E]) Equal

func (s Set[E]) Equal(other Set[E]) bool

Equal returns true if and only if s is equal (as a set) to other. Two sets are equal if their membership is identical. (In practice, this means same elements, order doesn't matter)

func (Set[E]) Has

func (s Set[E]) Has(item E) bool

Has returns true if and only if item is contained in the set.

func (Set[E]) HasAll

func (s Set[E]) HasAll(items ...E) bool

HasAll returns true if and only if all items are contained in the set.

func (Set[E]) HasAny

func (s Set[E]) HasAny(items ...E) bool

HasAny returns true if any items are contained in the set.

func (Set[E]) Insert

func (s Set[E]) Insert(items ...E) Set[E]

Insert adds items to the set.

func (Set[E]) Intersection

func (s Set[E]) Intersection(other Set[E]) Set[E]

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

func (Set[E]) IsSuperset

func (s Set[E]) IsSuperset(other Set[E]) bool

IsSuperset returns true if and only if s is a superset of other.

func (Set[E]) Len

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

Len returns the size of the set.

func (Set[E]) PopAny

func (s Set[E]) PopAny() (E, bool)

PopAny returns a single element from the set.

func (Set[E]) Slice

func (s Set[E]) Slice() []E

Slice returns a slice of the items in random order.

func (Set[E]) Union

func (s Set[E]) Union(other Set[E]) Set[E]

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

Jump to

Keyboard shortcuts

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