Documentation ¶
Index ¶
- func Difference[T comparable](setA Set[T], setB Set[T]) []T
- func FindDuplicates[T comparable](items []T) []T
- func FindUnique[T comparable](values []T) []T
- func Intersection[T comparable](setA Set[T], setB Set[T]) []T
- func IsCompleteBipartiteGraph[T comparable](setA map[T]Set[T], setB Set[T]) (disconnectedNodeALabels []T, disconnectedNodeBLabels []T)
- func IsSubset[T comparable](sourceSlice []T, targetSlice []T) bool
- func Separate[T any, K comparable](setA []T, setB []T, keyFn func(T) K) (uniqueA []T, common []T, uniqueB []T)
- type Set
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Difference ¶
func Difference[T comparable](setA Set[T], setB Set[T]) []T
func FindDuplicates ¶
func FindDuplicates[T comparable](items []T) []T
FindDuplicates returns a slice of duplicates if any.
func FindUnique ¶
func FindUnique[T comparable](values []T) []T
FindUnique returns the slice of unique values.
func Intersection ¶
func Intersection[T comparable](setA Set[T], setB Set[T]) []T
func IsCompleteBipartiteGraph ¶
func IsCompleteBipartiteGraph[T comparable](setA map[T]Set[T], setB Set[T]) (disconnectedNodeALabels []T, disconnectedNodeBLabels []T)
IsCompleteBipartiteGraph checks whether every node in setA and setB form a complete bipartite graph. In setA, a Set[T] map value is a node, with the map key as the node label. In setB, a key-value pair is a node, and the key is the node label. For two nodes to be connected, the element in setB must be in the Set[T] value of setA.
func IsSubset ¶
func IsSubset[T comparable](sourceSlice []T, targetSlice []T) bool
IsSubset return true if sourceSlice is a subset of targetSlice
func Separate ¶
func Separate[T any, K comparable](setA []T, setB []T, keyFn func(T) K) (uniqueA []T, common []T, uniqueB []T)
Separate splits setA and setB into three separate sets of elements: unique elements in setA, common elements in setA and setB, and unique elements in setB. The keyFn is used to compare the elements of setA and setB.
This implementation uses setA to populate the first and second return values, and setB to populate the third return value. Consequently, 'uniqueA' and 'common' return values will contain whatever data is contained in setA. (i.e., if setA is a slice of structs, some fields of setA may be populated, whereas some fields in setB may not be populated, and vice versa). If setA has more information than setB, the 'uniqueA' and 'common' return values will contain more field-level data than the 'uniqueB' return value, and vice versa.
Types ¶
type Set ¶
type Set[T comparable] map[T]struct{}
func FromSlice ¶
func FromSlice[T comparable](slices ...[]T) Set[T]
func FromSlicePtr ¶
func FromSlicePtr[T comparable](items *[]T) Set[T]
func FromSliceWithKey ¶
func FromSliceWithKey[T any, K comparable](keyFn func(T) K, slices ...[]T) Set[K]
func New ¶
func New[T comparable](elements ...T) Set[T]
func Union ¶
func Union[T comparable](sets ...Set[T]) Set[T]