Documentation
¶
Overview ¶
Package slice provides generic slice utilities such as binary search and sorting.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bsearch ¶
func Bsearch[T any](slice []T, compare func(target T) CompareType) int
Bsearch performs a binary search on a sorted slice. The compare function should return one of TARGET_SMALL, EQUAL, or TARGET_BIG for the probed element. It returns the index i such that compare(slice[i]) == EQUAL, or -1 if no such element exists.
func IsSorted ¶
IsSorted verifies that slice is sorted. It returns true if for all adjacent elements a, b in slice, compare(a, b) is true.
func ParallelSort ¶
ParallelSort performs a parallel merge sort on slice using compare. level is the maximum recursion depth to parallelize.
Types ¶
type CompareType ¶
type CompareType int
CompareType indicates the relation of the probed element to the target.
const ( // TARGET_SMALL indicates the target is larger than the probed element; search right. TARGET_SMALL CompareType = -1 // EQUAL indicates the target matches the probed element. EQUAL CompareType = 0 // TARGET_BIG indicates the target is smaller than the probed element; search left. TARGET_BIG CompareType = 1 )
Click to show internal directories.
Click to hide internal directories.