sets

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2023 License: Apache-2.0 Imports: 1 Imported by: 5

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

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 New

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

New returns a new Set of the given items.

func (Set[T]) Delete

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

Delete removes the item, and returns an updated Set.

func (Set[T]) Difference

func (s Set[T]) Difference(s2 Set[T]) Set[T]

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

func (s Set[T]) Equal(s2 Set[T]) bool

Equal returns true if s is equal (as a set) to s2.

Two sets are equal if their membership is identical.

func (Set[T]) Has

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

Has returns true if item is contained in the set.

func (Set[T]) HasAll

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

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

func (Set[T]) HasAny

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

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

func (Set[T]) Insert

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

Insert inserts items into the set and returns an updated Set.

func (Set[T]) Intersection

func (s Set[T]) Intersection(s2 Set[T]) Set[T]

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

func (s Set[T]) IsSuperset(s2 Set[T]) bool

IsSuperset returns true if s is a superset of s2.

func (Set[T]) Len

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

Len returns the size of the set.

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

func (s Set[T]) SortedList(sorter func(x, y T) bool) []T

SortedList returns a slice with all the items sorted using the sort function.

The sort func is passed through to sort.Slice.

func (Set[T]) Union

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

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}

Jump to

Keyboard shortcuts

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