Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LinearSearch ¶
func LinearSearch[E constraints.Ordered](x []E, target E) (int, bool)
LinearSearch searches for target in a sorted slice and returns the position where target is found, or the position where target would appear in the sort order; it also returns a bool saying whether the target is really found in the slice. The slice must be sorted in increasing order. Note: Binary-search was compared using the benchmarks. The following code is equivalent to the linear search above:
pos := sort.Search(len(x), func(i int) bool { return target < x[i] })
The binary search wins for very large boundary sets, but the linear search performs better up through arrays between 256 and 512 elements, so we continue to prefer linear search.
func LinearSearchFunc ¶
LinearSearchFunc works like LinearSearch, but uses a custom comparison function. The slice must be sorted in increasing order, where "increasing" is defined by cmp. cmp(a, b) is expected to return an integer comparing the two parameters: 0 if a == b, a negative number if a < b and a positive number if a > b.
func Reverse ¶ added in v1.2.7
func Reverse[S ~[]E, E any](x S)
Reverse reorder a slice of any ordered type in reverse order.
func SplitN ¶
SplitN slices s into subslices and returns a slice of the subslices .
The count determines the number of subslices to return:
n > 0: at most n subslices; the last subslices will be the unsplit remainder. n == 0: the result is nil (zero subslices) n < 0: all subslices as n == len(s)
Edge cases for s and sep (for example, empty strings) are handled as described in the documentation for Split.
Types ¶
This section is empty.