btsgutils

package
v0.21.4 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains[T comparable](slice []T, item T) bool

Contains returns true if the slice contains the item, false otherwise.

func ContainsDuplicate

func ContainsDuplicate[T any](arr []T) bool

ContainsDuplicate checks if there are any duplicate elements in the slice. ex: ContainsDuplicate([]int{4, 2, 7, 1, 1}) == true

func ContainsDuplicateDeepEqual

func ContainsDuplicateDeepEqual[T any](multihops []T) bool

ContainsDuplicateDeepEqual returns true if there are duplicates in the slice by performing deep comparison. This is useful for comparing matrices or slices of pointers. Returns false if there are no deep equal duplicates.

func Filter

func Filter[T interface{}](filter func(T) bool, s []T) []T

func GetRandomSubset

func GetRandomSubset[T any](slice []T) []T

GetRandomSubset returns a random subset of the given slice

func MakeNew

func MakeNew[T any]() T

MakeNew makes a new instance of generic T. if T is a pointer, makes a new instance of the underlying struct via reflection, and then a pointer to it.

func MergeSlices

func MergeSlices[T any](slice1, slice2 []T, less LessFunc[T]) []T

MergeSlices efficiently merges two sorted slices into a single sorted slice. The resulting slice contains all elements from slice1 and slice2, sorted according to the less function. The input slices must be sorted in ascending order according to the less function. The less function takes two elements of type T and returns a boolean value indicating whether the first element is less than the second element. The function returns a new slice containing all elements from slice1 and slice2, sorted according to the less function. The function does not modify the input slices.

func ReverseSlice

func ReverseSlice[T any](s []T) []T

ReverseSlice reverses the input slice in place. Does mutate argument. ex: ReverseSlice([]int{4, 2, 7, 1, 3}) == [3 1 7 2 4]

func SortSlice

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

SortSlice sorts a slice of type T elements that implement constraints.Ordered. Mutates input slice s ::::: SortSlice([]int{4, 2, 7, 1, 3}) == [1 2 3 4 7]

Types

type LessFunc

type LessFunc[T any] func(a, b T) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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