Documentation
¶
Overview ¶
Package sets provides functionality for creating and manipulating set data structures.
Index ¶
- func Add[K comparable](s *Set[K], k K)
- func AddAll[K comparable](s *Set[K], ks ...K)
- func Contains[K comparable](s Set[K], k K) bool
- func FromSet[C comparable](set Set[C]) (s []C)
- func IsSubsetOf[T comparable](a, b Set[T]) bool
- func IsSupersetOf[T comparable](a, b Set[T]) bool
- func Remove[K comparable](s *Set[K], k K)
- func RemoveAll[K comparable](s *Set[K], keys ...K)
- type Set
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 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 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.