sets

package
v0.12.6 Latest Latest
Warning

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

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

Documentation

Overview

Package sets provides functionality for creating and manipulating set data structures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add[K comparable](s *Set[K], k K)

Add adds a new element to the set. Modifies the set in place, does not return a new set.

func AddAll

func AddAll[K comparable](s *Set[K], ks ...K)

AddAll adds a new element to the set. Modifies the set in place, does not return a new set.

func Contains

func Contains[K comparable](s Set[K], k K) bool

Contains returns true if the set contains the element.

func FromSet

func FromSet[C comparable](set Set[C]) (s []C)

FromSet returns a slice from a sets.

func IsSubsetOf

func IsSubsetOf[T comparable](a, b Set[T]) bool

IsSubsetOf checks if a is a subset of b. Returns true if a is a subset of b, false otherwise.

func IsSupersetOf

func IsSupersetOf[T comparable](a, b Set[T]) bool

IsSupersetOf checks if a is a superset of b. Returns true if a is a superset of b, false otherwise.

func Remove

func Remove[K comparable](s *Set[K], k K)

Remove removes an element from the set. Modifies the set in place, does not return a new set.

func RemoveAll

func RemoveAll[K comparable](s *Set[K], keys ...K)

RemoveAll removes all elements passed as arguments from the set. Modifies the set in place, does not return a new set.

Types

type Set

type Set[T comparable] map[T]bool

Set is a set of values. Just a wrapper around a map where the keys are the sets elements and the values are always true.

func Difference

func Difference[K comparable](s1, s2 Set[K]) (s Set[K])

Difference returns a new set with the elements that are in the first set but not in the second. Returns a new set, does not modify the original sets.

func Intersection

func Intersection[K comparable](s1, s2 Set[K]) (s Set[K])

Intersection returns a new set with the elements that are in both sets. Returns a new sets, does not modify the original sets.

func ToSet

func ToSet[C comparable](slice []C) (s Set[C])

ToSet returns a sets from a slice.

func Union

func Union[T comparable](a, b Set[T]) (s Set[T])

Union returns a new set with the elements that are in either set. Returns a new set, does not modify the original set.

Jump to

Keyboard shortcuts

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