set

package
v1.0.0-pre3 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Provides a generic implementation of a set of elements.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Disjoint

func Disjoint[Key comparable](a, b Set[Key], sets ...Set[Key]) bool

Disjoint checks if sets are disjoint: ⋂(a, b, sets) = ∅

func Equal

func Equal[Key comparable](a, b Set[Key], sets ...Set[Key]) bool

Equal checks if sets are equal: ⋂(a, b, sets...) = ⋃(a, b, sets...)

Types

type Set

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

Set is a generic set of elements (keys).

func Difference

func Difference[Key comparable](a, b Set[Key], sets ...Set[Key]) Set[Key]

Difference returns the difference of all the sets: a ∖ b ∖ sets[0] ∖ sets[1] ...

func Intersection

func Intersection[Key comparable](a, b Set[Key], sets ...Set[Key]) Set[Key]

Intersetion returns the intersection of all the sets: ⋂(a, b, sets) = a ∩ b ∩ sets[0] ∩ sets[1] ...

func New

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

New creates a new set that contains all the given keys.

func SymmetricDifference

func SymmetricDifference[Key comparable](a, b Set[Key], sets ...Set[Key]) Set[Key]

SymmetricDifference returns the difference between the union and intersection of all the sets: ⋃(a, b, sets) ∖ ⋂(a, b, sets).

func Union

func Union[Key comparable](a, b Set[Key], sets ...Set[Key]) Set[Key]

Union returns the union of all the sets: ⋃(a, b, sets) = a ∪ b ∪ sets[0] ∪ sets[1] ...

func (Set[Key]) Add

func (s Set[Key]) Add(key Key, keys ...Key)

Add inserts keys into the set.

func (Set[Key]) Contains

func (s Set[Key]) Contains(key Key, keys ...Key) bool

Contains checks if the set contains all of the given keys.

func (Set[Key]) Copy

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

Copy creates a deep copy of the set. Will never return nil.

func (Set[Key]) Del

func (s Set[Key]) Del(key Key, keys ...Key)

Del removes keys from the set.

func (Set[Key]) Elements

func (s Set[Key]) Elements() []Key

Elements returns all the keys in the set as an unordered slice.

func (Set[Key]) Intersect

func (s Set[Key]) Intersect(a Set[Key], sets ...Set[Key])

Intersect is like Intersection, but modifies the set in place.

func (Set[Key]) IsSubsetOf

func (s Set[Key]) IsSubsetOf(other Set[Key]) (ok bool, proper bool)

IsSubsetOf returns a pair of values:

  • ok=true if s is a subset of other
  • proper=true if s is a proper subset (i.e., !Equal(s, other)))

func (Set[Key]) IsSupersetOf

func (s Set[Key]) IsSupersetOf(other Set[Key]) (ok bool, proper bool)

IsSupersetOf returns a pair of values:

  • ok=true if s is a superset of other
  • proper=true if s is a proper superset (i.e., !Equal(s, other)))

func (Set[Key]) Remove

func (s Set[Key]) Remove(a Set[Key], sets ...Set[Key])

Remove is like Difference, but modifies the set in place.

func (Set[Key]) SymmetricRemove

func (s Set[Key]) SymmetricRemove(a Set[Key], sets ...Set[Key])

SymmetricRemove is like SymmetricDifference, but modifies the set in place.

func (Set[Key]) Update

func (s Set[Key]) Update(a Set[Key], sets ...Set[Key])

Update is like Union, but modifies the set in place.

Jump to

Keyboard shortcuts

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