misc

package
v0.0.0-...-3e50352 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxInt32 = int32(1<<31 - 1)
)

Variables

This section is empty.

Functions

func Contains

func Contains[T any](arr []T, target T) bool

func Copy

func Copy[T any](src []T) []T

func EqualSlices

func EqualSlices[T comparable](a, b []T) bool

func Filter

func Filter[A any](arr []A, f func(A) bool) []A

func FilterByArray

func FilterByArray[A any, B bool](arr []A, filter []B) []A

func Find

func Find[A any](items []A, predicate func(A) bool) (value A, found bool)

func Fold

func Fold[A, B any](arr []A, f func(B, A) B, initval B) B

same as Reduce

func GetElementsByIndexes

func GetElementsByIndexes[T any](arr []T, ixs []int) []T

func GetRandomBytes

func GetRandomBytes(n int) []byte

func GetRandomElements

func GetRandomElements[T any](arr []T, n int, repetitions bool) []T

func HasDuplicates

func HasDuplicates[T comparable](arr []T) bool

func HashKey

func HashKey(key string) int

Fowler-Noll-Vo hash (FNV-1a) algorithm

func Map

func Map[T any, M any](arr []T, f func(T) M) []M

func Max

func Max[T Ordered](a, b T) T

func Max_Branchless

func Max_Branchless(a, b int) int

func Min

func Min[T Ordered](a, b T) T

func Min_Branchless

func Min_Branchless(a, b int) int

func Permutations

func Permutations[T any](arr []T) [][]T

func RangeSlice

func RangeSlice(a, b int) []int

func Reduce

func Reduce[A, B any](collection []A, accumulator func(B, A) B, initialValue B) B

func Reverse

func Reverse[T any](arr []T, start, end int)

in place reverse

func Rotate

func Rotate[T any](arr []T, k int)

rotate slice k steps in place

func Sequence

func Sequence[T Number](min, max, step T) []T

func SubArray

func SubArray[T any](data []T, index int, length ...int) []T

/ length ...int means it's a variadic parameter, it's optional

func Zip

func Zip[T1 any, T2 any, R any](arr1 []T1, arr2 []T2, f func(T1, T2) R) []R

Types

type Number

type Number interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | UnsignedNumber | ~float32 | ~float64
}

type Ordered

type Ordered interface {
	Number | ~string
}

type UnsignedNumber

type UnsignedNumber interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Jump to

Keyboard shortcuts

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