1
0
mirror of https://github.com/golang/go synced 2024-11-22 14:34:45 -07:00

sort: add available godoc link

Change-Id: I64645fef0ffd1cea7c7710ec974520f85e0f7496
Reviewed-on: https://go-review.googlesource.com/c/go/+/539579
Run-TryBot: shuang cui <imcusg@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: qiulaidongfeng <2645477756@qq.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
This commit is contained in:
cui fliter 2023-11-03 19:54:41 +08:00 committed by Gopher Robot
parent d59bd25a30
commit 7ccddf040a
3 changed files with 17 additions and 17 deletions

View File

@ -117,7 +117,7 @@ func Find(n int, cmp func(int) int) (i int, found bool) {
// Convenience wrappers for common cases.
// SearchInts searches for x in a sorted slice of ints and returns the index
// as specified by Search. The return value is the index to insert x if x is
// as specified by [Search]. The return value is the index to insert x if x is
// not present (it could be len(a)).
// The slice must be sorted in ascending order.
func SearchInts(a []int, x int) int {
@ -125,7 +125,7 @@ func SearchInts(a []int, x int) int {
}
// SearchFloat64s searches for x in a sorted slice of float64s and returns the index
// as specified by Search. The return value is the index to insert x if x is not
// as specified by [Search]. The return value is the index to insert x if x is not
// present (it could be len(a)).
// The slice must be sorted in ascending order.
func SearchFloat64s(a []float64, x float64) int {
@ -140,11 +140,11 @@ func SearchStrings(a []string, x string) int {
return Search(len(a), func(i int) bool { return a[i] >= x })
}
// Search returns the result of applying SearchInts to the receiver and x.
// Search returns the result of applying [SearchInts] to the receiver and x.
func (p IntSlice) Search(x int) int { return SearchInts(p, x) }
// Search returns the result of applying SearchFloat64s to the receiver and x.
// Search returns the result of applying [SearchFloat64s] to the receiver and x.
func (p Float64Slice) Search(x float64) int { return SearchFloat64s(p, x) }
// Search returns the result of applying SearchStrings to the receiver and x.
// Search returns the result of applying [SearchStrings] to the receiver and x.
func (p StringSlice) Search(x string) int { return SearchStrings(p, x) }

View File

@ -14,12 +14,12 @@ import (
//
// The sort is not guaranteed to be stable: equal elements
// may be reversed from their original order.
// For a stable sort, use SliceStable.
// For a stable sort, use [SliceStable].
//
// The less function must satisfy the same requirements as
// the Interface type's Less method.
//
// Note: in many situations, the newer slices.SortFunc function is more
// Note: in many situations, the newer [slices.SortFunc] function is more
// ergonomic and runs faster.
func Slice(x any, less func(i, j int) bool) {
rv := reflectlite.ValueOf(x)
@ -36,7 +36,7 @@ func Slice(x any, less func(i, j int) bool) {
// The less function must satisfy the same requirements as
// the Interface type's Less method.
//
// Note: in many situations, the newer slices.SortStableFunc function is more
// Note: in many situations, the newer [slices.SortStableFunc] function is more
// ergonomic and runs faster.
func SliceStable(x any, less func(i, j int) bool) {
rv := reflectlite.ValueOf(x)
@ -47,7 +47,7 @@ func SliceStable(x any, less func(i, j int) bool) {
// SliceIsSorted reports whether the slice x is sorted according to the provided less function.
// It panics if x is not a slice.
//
// Note: in many situations, the newer slices.IsSortedFunc function is more
// Note: in many situations, the newer [slices.IsSortedFunc] function is more
// ergonomic and runs faster.
func SliceIsSorted(x any, less func(i, j int) bool) bool {
rv := reflectlite.ValueOf(x)

View File

@ -40,7 +40,7 @@ type Interface interface {
// It makes one call to data.Len to determine n and O(n*log(n)) calls to
// data.Less and data.Swap. The sort is not guaranteed to be stable.
//
// Note: in many situations, the newer slices.SortFunc function is more
// Note: in many situations, the newer [slices.SortFunc] function is more
// ergonomic and runs faster.
func Sort(data Interface) {
n := data.Len()
@ -100,7 +100,7 @@ func Reverse(data Interface) Interface {
// IsSorted reports whether data is sorted.
//
// Note: in many situations, the newer slices.IsSortedFunc function is more
// Note: in many situations, the newer [slices.IsSortedFunc] function is more
// ergonomic and runs faster.
func IsSorted(data Interface) bool {
n := data.Len()
@ -161,34 +161,34 @@ func (x StringSlice) Sort() { Sort(x) }
// Ints sorts a slice of ints in increasing order.
//
// Note: as of Go 1.22, this function simply calls slices.Sort.
// Note: as of Go 1.22, this function simply calls [slices.Sort].
func Ints(x []int) { intsImpl(x) }
// Float64s sorts a slice of float64s in increasing order.
// Not-a-number (NaN) values are ordered before other values.
//
// Note: as of Go 1.22, this function simply calls slices.Sort.
// Note: as of Go 1.22, this function simply calls [slices.Sort].
func Float64s(x []float64) { float64sImpl(x) }
// Strings sorts a slice of strings in increasing order.
//
// Note: as of Go 1.22, this function simply calls slices.Sort.
// Note: as of Go 1.22, this function simply calls [slices.Sort].
func Strings(x []string) { stringsImpl(x) }
// IntsAreSorted reports whether the slice x is sorted in increasing order.
//
// Note: as of Go 1.22, this function simply calls slices.IsSorted.
// Note: as of Go 1.22, this function simply calls [slices.IsSorted].
func IntsAreSorted(x []int) bool { return intsAreSortedImpl(x) }
// Float64sAreSorted reports whether the slice x is sorted in increasing order,
// with not-a-number (NaN) values before any other values.
//
// Note: as of Go 1.22, this function simply calls slices.IsSorted.
// Note: as of Go 1.22, this function simply calls [slices.IsSorted].
func Float64sAreSorted(x []float64) bool { return float64sAreSortedImpl(x) }
// StringsAreSorted reports whether the slice x is sorted in increasing order.
//
// Note: as of Go 1.22, this function simply calls slices.IsSorted.
// Note: as of Go 1.22, this function simply calls [slices.IsSorted].
func StringsAreSorted(x []string) bool { return stringsAreSortedImpl(x) }
// Notes on stable sorting: