Documentation
¶
Index ¶
- func Contains[T comparable](slice []T, item T) bool
- func ContainsDuplicate[T any](arr []T) bool
- func ContainsDuplicateDeepEqual[T any](multihops []T) bool
- func Filter[T interface{}](filter func(T) bool, s []T) []T
- func GetRandomSubset[T any](slice []T) []T
- func MakeNew[T any]() T
- func MergeSlices[T any](slice1, slice2 []T, less LessFunc[T]) []T
- func ReverseSlice[T any](s []T) []T
- func SortSlice[T constraints.Ordered](s []T)
- type LessFunc
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 ¶
ContainsDuplicate checks if there are any duplicate elements in the slice. ex: ContainsDuplicate([]int{4, 2, 7, 1, 1}) == true
func ContainsDuplicateDeepEqual ¶
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 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 ¶
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]