slice

package
v4.0.3-hotfix Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: GPL-3.0 Imports: 2 Imported by: 26

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func IntersectionByteSlices

func IntersectionByteSlices(s ...[][]byte) [][]byte

IntersectionByteSlices returns the common elements between sets of byte slices.

func IntersectionInt64

func IntersectionInt64(s ...[]int64) []int64

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

func IntersectionUint64(s ...[]uint64) []uint64

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 IsInInt64

func IsInInt64(a int64, b []int64) bool

IsInInt64 returns true if a is in b and False otherwise.

func IsInSlots

func IsInSlots(a primitives.Slot, b []primitives.Slot) bool

IsInSlots returns true if a is in b and False otherwise.

func IsInUint64

func IsInUint64(a uint64, b []uint64) bool

IsInUint64 returns true if a is in b and False otherwise.

func IsUint64Sorted

func IsUint64Sorted(a []uint64) bool

IsUint64Sorted verifies if a uint64 slice is sorted in ascending order.

func NotInt64

func NotInt64(a, b []int64) []int64

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

func NotUint64(a, b []uint64) []uint64

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 SetUint64

func SetUint64(a []uint64) []uint64

SetUint64 returns a slice with only unique values from the provided list of indices.

func SplitCommaSeparated

func SplitCommaSeparated(arr []string) []string

SplitCommaSeparated values from the list. Example: []string{"a,b", "c,d"} becomes []string{"a", "b", "c", "d"}.

func SplitOffset

func SplitOffset(listSize, chunks, index uint64) uint64

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

func SubsetUint64(a, b []uint64) bool

SubsetUint64 returns true if the first array is completely contained in the second array with time complexity of approximately o(n).

func UnionByteSlices

func UnionByteSlices(s ...[][]byte) [][]byte

UnionByteSlices returns the all elements between sets of byte slices.

func UnionInt64

func UnionInt64(s ...[]int64) []int64

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

func UnionUint64(s ...[]uint64) []uint64

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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