utils

package
v5.0.5 Latest Latest
Warning

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

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

Documentation

Overview

Package utils implements various helper functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alias1D

func Alias1D[V any](x, y []V) bool

Alias1D returns true if x and y share the same base array. Taken from http://golang.org/src/pkg/math/big/nat.go#L340 .

func Alias2D

func Alias2D[V any](x, y [][]V) bool

Alias2D returns true if x and y share the same base array. Taken from http://golang.org/src/pkg/math/big/nat.go#L340 .

func AllDistinct

func AllDistinct[V comparable](s []V) bool

AllDistinct returns true if all elements in s are distinct, and false otherwise.

func BitReverse64

func BitReverse64[V uint64 | uint32 | int | int64](index V, bitLen int) uint64

BitReverse64 returns the bit-reverse value of the input value, within a context of 2^bitLen.

func BitReverseInPlaceSlice

func BitReverseInPlaceSlice[V any](slice []V, N int)

BitReverseInPlaceSlice applies an in-place bit-reverse permutation on the input slice.

func EqualSlice

func EqualSlice[V comparable](a, b []V) (v bool)

EqualSlice checks the equality between two slices of comparables.

func GCD

func GCD[V uint64 | uint32 | int | int64](a, b V) V

GCD computes the greatest common divisor between a and b.

func GetDistincts

func GetDistincts[V comparable](v []V) (vd []V)

GetDistincts returns the list of distinct elements in v.

func GetKeys

func GetKeys[K constraints.Ordered, V any](m map[K]V) (keys []K)

GetKeys returns the keys of the input map. Order is not guaranteed.

func GetSortedKeys

func GetSortedKeys[K constraints.Ordered, V any](m map[K]V) (keys []K)

GetSortedKeys returns the sorted keys of a map.

func HammingWeight64

func HammingWeight64[V uint64 | uint32 | int | int64](x V) V

HammingWeight64 returns the hammingweight if the input value.

func IsInSlice

func IsInSlice[V comparable](x V, slice []V) (v bool)

IsInSlice checks if x is in slice.

func IsNil

func IsNil(i interface{}) bool

IsNil returns true either type or value are nil. Only interfaces or pointers to objects should be passed as argument.

func Max

func Max[V constraints.Ordered](a, b V) (r V)

Max returns the maximum value of the two inputs.

func MaxSlice

func MaxSlice[V constraints.Ordered](slice []V) (max V)

MaxSlice returns the maximum value in the slice.

func Min

func Min[V constraints.Ordered](a, b V) (r V)

Min returns the minimum value of the two inputs.

func MinSlice

func MinSlice[V constraints.Ordered](slice []V) (min V)

MinSlice returns the minimum value in the slice.

func Pointy

func Pointy[T Number](x T) *T

Pointy creates a new T variable and returns its pointer.

func PointyIntToPointUint64

func PointyIntToPointUint64(x *int) *uint64

PointyIntToPointUint64 converts *int to *uint64.

func RotateSlice

func RotateSlice[V any](s []V, k int) []V

RotateSlice returns a new slice corresponding to s rotated by k positions to the left.

func RotateSliceAllocFree

func RotateSliceAllocFree[V any](s []V, k int, sout []V)

RotateSliceAllocFree rotates slice s by k positions to the left and writes the result in sout. without allocating new memory.

func RotateSliceInPlace

func RotateSliceInPlace[V any](s []V, k int)

RotateSliceInPlace rotates slice s in place by k positions to the left.

func RotateSlotsNew

func RotateSlotsNew[V any](s []V, k int) (r []V)

RotateSlotsNew returns a new slice where the two half of the original slice are rotated each by k positions independently.

func SortSlice

func SortSlice[T constraints.Ordered](s []T)

SortSlice sorts a slice in place.

Types

type Number

type Number interface {
	cs.Complex | cs.Float | cs.Integer
}

Directories

Path Synopsis
Package bignum implements arbitrary precision arithmetic for integers, reals and complex numbers.
Package bignum implements arbitrary precision arithmetic for integers, reals and complex numbers.
Package buffer implement methods for efficiently writing and reading values to and from io.Writer and io.Reader that also expose their internal buffers.
Package buffer implement methods for efficiently writing and reading values to and from io.Writer and io.Reader that also expose their internal buffers.
Package factorization implements various algorithms for efficient factoring integers of small to medium size.
Package factorization implements various algorithms for efficient factoring integers of small to medium size.
Package sampling implements secure sampling of bytes and integers.
Package sampling implements secure sampling of bytes and integers.
Package structs implements helpers to generalize vectors and matrices of structs, as well as their serialization.
Package structs implements helpers to generalize vectors and matrices of structs, as well as their serialization.

Jump to

Keyboard shortcuts

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