Documentation ¶
Overview ¶
set is a map of keys with unit-values (`struct{}{}`). These values do not take up additional space. This allows the map to be used as a set, indicating whether an element is present (as a key) or not. This is a basic utility. For highly specialized and optimized use cases, look for a suitable specialized implementation.
Index ¶
- func Contains[K comparable](set map[K]struct{}, e K) bool
- func ContainsAll[K comparable](a, b map[K]struct{}) bool
- func Create[K comparable](elements ...K) map[K]struct{}
- func Difference[K comparable](set, other map[K]struct{}) map[K]struct{}
- func IdenticalTo[K comparable](a map[K]struct{}) func(set map[K]struct{}) bool
- func Insert[K comparable](set map[K]struct{}, e K)
- func InsertMany[K comparable](set map[K]struct{}, elms []K)
- func Intersection[K comparable](a, b map[K]struct{}) map[K]struct{}
- func Merge[K comparable](dst, src map[K]struct{})
- func NotIdenticalTo[K comparable](a map[K]struct{}) func(set map[K]struct{}) bool
- func NotSubsetOf[K comparable](a map[K]struct{}) func(set map[K]struct{}) bool
- func NotSupersetOf[K comparable](a map[K]struct{}) func(set map[K]struct{}) bool
- func Remove[K comparable](set map[K]struct{}, e K)
- func RemoveMany[K comparable](set map[K]struct{}, elms []K)
- func SubsetOf[K comparable](a map[K]struct{}) func(set map[K]struct{}) bool
- func Subtract[K comparable](set, other map[K]struct{})
- func SupersetOf[K comparable](a map[K]struct{}) func(set map[K]struct{}) bool
- func SymmetricDifference[K comparable](set, other map[K]struct{}) map[K]struct{}
- func Union[K comparable](a, b map[K]struct{}) map[K]struct{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains[K comparable](set map[K]struct{}, e K) bool
Contains tests for the presence of element `e` and returns true iff present.
func ContainsAll ¶
func ContainsAll[K comparable](a, b map[K]struct{}) bool
ContainsAll checks whether all elements of `b` are present in `a`.
func Create ¶
func Create[K comparable](elements ...K) map[K]struct{}
Create creates and initializes a new map[K]struct{} for use as a set. All provided elements will immediately be included in the set. Initialization assumes that elements are unique; immediately allocates room for `len(elements)` elements in the map.
func Difference ¶
func Difference[K comparable](set, other map[K]struct{}) map[K]struct{}
Difference creates a new set containing all elements from `set` that are not present in `other`.
See: <https://en.wikipedia.org/wiki/Set_(mathematics)#Basic_operations>
FIXME unused, untested
func IdenticalTo ¶
func IdenticalTo[K comparable](a map[K]struct{}) func(set map[K]struct{}) bool
IdenticalTo constructs a closure with set `a`, such that it can be used repeated to test whether a given set `b` is identical to `a`.
func Insert ¶
func Insert[K comparable](set map[K]struct{}, e K)
Insert inserts an element into the map (with the unit-value).
func InsertMany ¶
func InsertMany[K comparable](set map[K]struct{}, elms []K)
InsertMany allows inserting any number of elements provided through vararg.
func Intersection ¶
func Intersection[K comparable](a, b map[K]struct{}) map[K]struct{}
Intersection produces a set of all elements present in both `a` and `b`. FIXME unused, untested
func NotIdenticalTo ¶
func NotIdenticalTo[K comparable](a map[K]struct{}) func(set map[K]struct{}) bool
NotIdenticalTo constructs a closure with set `a`, such that it can be used repeated to test whether a given set `b` is NOT identical to `a`.
func NotSubsetOf ¶
func NotSubsetOf[K comparable](a map[K]struct{}) func(set map[K]struct{}) bool
NotSubsetOf constructs a closure with set `a`, such that it can be used repeated to test whether a given set `b` is NOT a subset of `a`.
func NotSupersetOf ¶
func NotSupersetOf[K comparable](a map[K]struct{}) func(set map[K]struct{}) bool
NotSupersetOf constructs a closure with set `a`, such that it can be used repeatedly to test whether a given set `b` is NOT a superset of `a`.
func Remove ¶
func Remove[K comparable](set map[K]struct{}, e K)
Remove removes an element if present in the map.
func RemoveMany ¶
func RemoveMany[K comparable](set map[K]struct{}, elms []K)
RemoveMany removes any number of elements as provided through vararg.
func SubsetOf ¶
func SubsetOf[K comparable](a map[K]struct{}) func(set map[K]struct{}) bool
SubsetOf constructs a closure with set `a`, such that it can be used repeated to test whether a given set `b` is a subset of `a`.
func Subtract ¶
func Subtract[K comparable](set, other map[K]struct{})
Subtract updates `set` by removing any element present in `other`.
See: <https://en.wikipedia.org/wiki/Set_(mathematics)#Basic_operations>
FIXME unused, untested
func SupersetOf ¶
func SupersetOf[K comparable](a map[K]struct{}) func(set map[K]struct{}) bool
SupersetOf constructs a closure with set `a`, such that it can be used repeatedly to test whether a given set `b` is a superset of `a`.
func SymmetricDifference ¶
func SymmetricDifference[K comparable](set, other map[K]struct{}) map[K]struct{}
SymmetricDifference produces the symmetric difference of `set` and `other`, by removing elements that are present in both sets, and keeping elements present in only one set.
See: <https://en.wikipedia.org/wiki/Set_(mathematics)#Basic_operations>
REMARK consider starting at size `0` to avoid excessive use when this function is performed on large sets. FIXME unused, untested
func Union ¶
func Union[K comparable](a, b map[K]struct{}) map[K]struct{}
Union produces a set of all elements present in either `a` or `b` (or both). FIXME unused, untested
Types ¶
This section is empty.