sets

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 0 Imported by: 12

Documentation

Overview

Package sets defines efficient operations for common set operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Intersect

func Intersect[T comparable](slices ...[]T) []T

Intersect finds the intersection of all slices, where intersection is defined as elements that exist in all slices. The elements in the returned slice will be in an undefined order - use IntersectStable to trade efficiency for ordering. Duplicate elements are removed. This function always returns an allocated slice, even if the intersection is the empty set.

It does not modify any of the given slices, but also does not deep copy any values. That means the returned slice may have elements that point to the same objects as in the original slice.

func IntersectMapKeys

func IntersectMapKeys[K comparable, V any](maps ...map[K]V) map[K]V

IntersectMapKeys finds the intersection of all m keys, where intersection is defined as keys that exist in all m. In the case where duplicate keys exist across maps, the value corresponding to the key in the first map is used. It always returns an allocated map, even if the intersection is the empty set.

It does not modify any of the given inputs, but also does not deep copy any values. That means the returned map may have keys and values that point to the same objects as in the original map.

func IntersectStable

func IntersectStable[T comparable](slices ...[]T) []T

IntersectStable has the same invariants Intersect, except it preserves the relative order of elements in the intersection. This function has a comparatively higher runtime complexity than Intersect.

func Subtract

func Subtract[T comparable](slices ...[]T) []T

Subtract finds the differece (subtraction), where difference is defined as the removal of all elements from s0 that exist in sn. The elements are returned in the order in which they appeared in s0. This function always returns an allocated slice, even if the difference is the empty set.

All duplicate elements that match a subtraction are removed. Duplicate elements that do not match a subtraction are preserved.

It does not modify any of the given slices, but also does not deep copy any values. That means the returned slice may have elements that point to the same objects as in the original slice.

func SubtractMapKeys

func SubtractMapKeys[K comparable, V any](maps ...map[K]V) map[K]V

SubtractMapKeys finds the differece (subtraction), where difference is defined as the removal of all keys from m0 that exist in mn. It always returns an allocated map, even if the difference is the empty set.

It does not modify any of the given inputs, but also does not deep copy any values. That means the returned map may have keys and values that point to the same objects as in the original map.

func Union

func Union[T comparable](slices ...[]T) []T

Union finds the union of all slices, where union is defined as the combination of all elements in all slices. The elements are returned in the order in which they first appear in the slices. Duplicate elements are removed. This function always returns an allocated slice, even if the union is the empty set.

It does not modify any of the given slices, but also does not deep copy any values. That means the returned slice may have elements that point to the same objects as in the original slice.

func UnionMapKeys

func UnionMapKeys[K comparable, V any](maps ...map[K]V) map[K]V

UnionMapKeys finds the union of all m, where union is defined as the combination of all keys in all m. In the case where duplicate keys exist across maps, the value corresponding to the key in the first map is used. It always returns an allocated map, even if the union is the empty set.

It does not modify any of the given inputs, but also does not deep copy any values. That means the returned map may have keys and values that point to the same objects as in the original map.

Types

This section is empty.

Jump to

Keyboard shortcuts

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