Documentation ¶
Overview ¶
Package slice implements set operations for specified data type
Currently types which are tested and supported are:
[]uint32 []int32 []string []float32 []uint64 []int64 []string []float64
Intersection, Union, Not , IsIn are the operations which are supported on slices
Index ¶
- func IntersectionByteSlices(s ...[][]byte) [][]byte
- func IntersectionInt64(s ...[]int64) []int64
- func IntersectionSlot(s ...[]primitives.Slot) []primitives.Slot
- func IntersectionUint64(s ...[]uint64) []uint64
- func IsInInt64(a int64, b []int64) bool
- func IsInSlots(a primitives.Slot, b []primitives.Slot) bool
- func IsInUint64(a uint64, b []uint64) bool
- func IsUint64Sorted(a []uint64) bool
- func NotInt64(a, b []int64) []int64
- func NotSlot(a, b []primitives.Slot) []primitives.Slot
- func NotUint64(a, b []uint64) []uint64
- func Reverse[E any](s []E) []E
- func SetUint64(a []uint64) []uint64
- func SplitCommaSeparated(arr []string) []string
- func SplitOffset(listSize, chunks, index uint64) uint64
- func SubsetUint64(a, b []uint64) bool
- func UnionByteSlices(s ...[][]byte) [][]byte
- func UnionInt64(s ...[]int64) []int64
- func UnionUint64(s ...[]uint64) []uint64
- func Unique[T comparable](a []T) []T
- func VerifyMaxLength[T any](v []T, max int) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IntersectionByteSlices ¶
IntersectionByteSlices returns the common elements between sets of byte slices.
func IntersectionInt64 ¶
IntersectionInt64 of any number of int64 slices with time complexity of approximately O(n) leveraging a map to check for element existence off by a constant factor of underlying map efficiency.
func IntersectionSlot ¶
func IntersectionSlot(s ...[]primitives.Slot) []primitives.Slot
IntersectionSlot of any number of types.Slot slices with time complexity of approximately O(n) leveraging a map to check for element existence off by a constant factor of underlying map efficiency.
func IntersectionUint64 ¶
IntersectionUint64 of any number of uint64 slices with time complexity of approximately O(n) leveraging a map to check for element existence off by a constant factor of underlying map efficiency.
func IsInSlots ¶
func IsInSlots(a primitives.Slot, b []primitives.Slot) bool
IsInSlots returns true if a is in b and False otherwise.
func IsInUint64 ¶
IsInUint64 returns true if a is in b and False otherwise.
func IsUint64Sorted ¶
IsUint64Sorted verifies if a uint64 slice is sorted in ascending order.
func NotInt64 ¶
NotInt64 returns the int64 in slice a that are not in slice b with time complexity of approximately O(n) leveraging a map to check for element existence off by a constant factor of underlying map efficiency.
func NotSlot ¶
func NotSlot(a, b []primitives.Slot) []primitives.Slot
NotSlot returns the types.Slot in slice b that are not in slice a with time complexity of approximately O(n) leveraging a map to check for element existence off by a constant factor of underlying map efficiency.
func NotUint64 ¶
NotUint64 returns the uint64 in slice b that are not in slice a with time complexity of approximately O(n) leveraging a map to check for element existence off by a constant factor of underlying map efficiency.
func Reverse ¶
func Reverse[E any](s []E) []E
Reverse reverses any slice in place Taken from https://github.com/faiface/generics/blob/8cf65f0b43803410724d8c671cb4d328543ba07d/examples/sliceutils/sliceutils.go
func SetUint64 ¶
SetUint64 returns a slice with only unique values from the provided list of indices.
func SplitCommaSeparated ¶
SplitCommaSeparated values from the list. Example: []string{"a,b", "c,d"} becomes []string{"a", "b", "c", "d"}.
func SplitOffset ¶
SplitOffset returns the start index of a given list splits into chunks, it computes (listsize * index) / chunks.
Spec pseudocode definition: def get_split_offset(list_size: int, chunks: int, index: int) -> int:
""" Returns a value such that for a list L, chunk count k and index i, split(L, k)[i] == L[get_split_offset(len(L), k, i): get_split_offset(len(L), k, i+1)] """ return (list_size * index) // chunks
func SubsetUint64 ¶
SubsetUint64 returns true if the first array is completely contained in the second array with time complexity of approximately o(n).
func UnionByteSlices ¶
UnionByteSlices returns the all elements between sets of byte slices.
func UnionInt64 ¶
UnionInt64 of any number of int64 slices with time complexity of approximately O(n) leveraging a map to check for element existence off by a constant factor of underlying map efficiency.
func UnionUint64 ¶
UnionUint64 of any number of uint64 slices with time complexity of approximately O(n) leveraging a map to check for element existence off by a constant factor of underlying map efficiency.
func Unique ¶
func Unique[T comparable](a []T) []T
Unique returns an array with duplicates filtered based on the type given
func VerifyMaxLength ¶
VerifyMaxLength takes a slice and a maximum length and validates the length.
Types ¶
This section is empty.