set

package module
v0.0.0-...-70333e7 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: MIT Imports: 0 Imported by: 0

Documentation

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]struct{}

func FromMapKey

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

FromMapKey returns a Set of type T with all keys from the given map.

func FromSlice

func FromSlice[T comparable](a []T) Set[T]

FromSlice returns a Set of type T with all elements from the given slice.

func Intersect

func Intersect[T comparable](s1, s2 Set[T]) Set[T]

Intersect returns a Set of type T with elements that exists in both of the given sets.

func Minus

func Minus[T comparable](s1, s2 Set[T]) Set[T]

Minus returns a Set of type T with elements that exists in the first but not the second given set.

func New

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

New creates an empty Set of type T.

func Union

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

Union returns a Set of type T with elements that exists in either of the given sets.

func (Set[T]) Add

func (s Set[T]) Add(k T)

Add adds an element to the set.

func (Set[T]) Copy

func (s Set[T]) Copy() Set[T]

Copy generates a copy of the set.

func (Set[T]) Del

func (s Set[T]) Del(k T)

Del deletes an element from the set

func (Set[T]) Eq

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

Eq checks if two sets are equal.

func (Set[T]) Filter

func (s Set[T]) Filter(p func(k T) bool) Set[T]

Filter filters the set by the given predicament and adds them to a new set for return.

func (Set[T]) FilterInPlace

func (s Set[T]) FilterInPlace(p func(k T) bool)

FilterInPlace filters the set by the given predicament and acts in-place.

func (Set[T]) Has

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

Has checks if an element is in the set.

func (Set[T]) IntersectWith

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

IntersectWith removes all elements from the current set if it's not in the given set.

func (Set[T]) Iterate

func (s Set[T]) Iterate(f func(k T))

Iterate iterates the set by calling the given function with each element in the set.

func (Set[T]) Len

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

Len returns the number of elements in the set.

func (Set[T]) MinusWith

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

MinusWith removes all elements from the current set if it's also in the given set.

func (Set[T]) ToSlice

func (s Set[T]) ToSlice() []T

ToSlice extracts all elements into a slice.

func (Set[T]) UnionWith

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

UnionWith adds all elements in the given set to the current set.

Jump to

Keyboard shortcuts

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