set

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: BSD-2-Clause Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equals

func Equals[T comparable](s1 Set[T], s2 Set[T]) bool

Equals compare two set, return true when have same elements

Types

type Set

type Set[T comparable] map[T]empty

Set implements set using hash table

func Convert

func Convert[T comparable, R comparable](s Set[T], convert func(v T) R) Set[R]

Convert return a new Set, contains values by applying convert func on original set

func Difference

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

Difference return difference set s2 from set s1 (s1-s2), which is a set of elements that are only in s1 but not in s2.

func Intersect

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

Intersect return intersection of two sets.

func New

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

New create new Set

func SymmetricDifference

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

SymmetricDifference return symmetric difference two sets, which is a set of elements in s1 and s2 but not in both (excluding the intersection).

func Union

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

Union return union of two sets.

func (Set[T]) Add

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

Add adds new element to Set

func (Set[T]) AddAll

func (s Set[T]) AddAll(values ...T)

AddAll adds new elements to Set

func (Set[T]) AddSet

func (s Set[T]) AddSet(set Set[T])

AddSet adds new elements of a new set to this Set

func (Set[T]) Contains

func (s Set[T]) Contains(value T) bool

Contains return if set contains the value

func (Set[T]) ContainsAny

func (s Set[T]) ContainsAny(values ...T) bool

ContainsAny return if set contains anyone of the values

func (Set[T]) Copy

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

Copy shallow copy a set

func (Set[T]) ForEach

func (s Set[T]) ForEach(f func(value T))

ForEach traverse all element in this set

func (Set[T]) Remove

func (s Set[T]) Remove(value T)

Remove remove element from set

func (Set[T]) RemoveAll

func (s Set[T]) RemoveAll(values ...T)

RemoveAll remove elements from Set

func (Set[T]) RemoveSet

func (s Set[T]) RemoveSet(set Set[T])

RemoveSet remove elements of a set from this Set

func (Set[T]) Select

func (s Set[T]) Select(predicate func(v T) bool) Set[T]

Select apply predicate on the origin set, return a new set contains the values match the predicate.

func (Set[T]) Size

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

Size return element count of this set

func (Set[T]) ToSlice

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

ToSlice put all element in a new slice, and return it

Jump to

Keyboard shortcuts

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