mirror of
https://github.com/golang/go
synced 2024-11-11 18:21:40 -07:00
sort: comments directing new code to use the slices package when applicable
Change-Id: I0d4e902736fb3a75d128a088901055bece6c1a71 Reviewed-on: https://go-review.googlesource.com/c/go/+/502555 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Eli Bendersky <eliben@google.com> Auto-Submit: Eli Bendersky <eliben@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Eli Bendersky <eliben@google.com>
This commit is contained in:
parent
17dcbd8662
commit
8faa79e91f
@ -39,6 +39,9 @@ type Interface interface {
|
||||
// Sort sorts data in ascending order as determined by the Less method.
|
||||
// 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
|
||||
// ergonomic and runs faster.
|
||||
func Sort(data Interface) {
|
||||
n := data.Len()
|
||||
if n <= 1 {
|
||||
@ -96,6 +99,9 @@ func Reverse(data Interface) Interface {
|
||||
}
|
||||
|
||||
// IsSorted reports whether data is sorted.
|
||||
//
|
||||
// Note: in many situations, the newer slices.IsSortedFunc function is more
|
||||
// ergonomic and runs faster.
|
||||
func IsSorted(data Interface) bool {
|
||||
n := data.Len()
|
||||
for i := n - 1; i > 0; i-- {
|
||||
@ -154,23 +160,35 @@ func (x StringSlice) Sort() { Sort(x) }
|
||||
// Convenience wrappers for common cases
|
||||
|
||||
// Ints sorts a slice of ints in increasing order.
|
||||
//
|
||||
// Note: consider using the newer slices.Sort function, which runs faster.
|
||||
func Ints(x []int) { Sort(IntSlice(x)) }
|
||||
|
||||
// Float64s sorts a slice of float64s in increasing order.
|
||||
// Not-a-number (NaN) values are ordered before other values.
|
||||
//
|
||||
// Note: consider using the newer slices.Sort function, which runs faster.
|
||||
func Float64s(x []float64) { Sort(Float64Slice(x)) }
|
||||
|
||||
// Strings sorts a slice of strings in increasing order.
|
||||
//
|
||||
// Note: consider using the newer slices.Sort function, which runs faster.
|
||||
func Strings(x []string) { Sort(StringSlice(x)) }
|
||||
|
||||
// IntsAreSorted reports whether the slice x is sorted in increasing order.
|
||||
//
|
||||
// Note: consider using the newer slices.IsSorted function, which runs faster.
|
||||
func IntsAreSorted(x []int) bool { return IsSorted(IntSlice(x)) }
|
||||
|
||||
// Float64sAreSorted reports whether the slice x is sorted in increasing order,
|
||||
// with not-a-number (NaN) values before any other values.
|
||||
//
|
||||
// Note: consider using the newer slices.IsSorted function, which runs faster.
|
||||
func Float64sAreSorted(x []float64) bool { return IsSorted(Float64Slice(x)) }
|
||||
|
||||
// StringsAreSorted reports whether the slice x is sorted in increasing order.
|
||||
//
|
||||
// Note: consider using the newer slices.IsSorted function, which runs faster.
|
||||
func StringsAreSorted(x []string) bool { return IsSorted(StringSlice(x)) }
|
||||
|
||||
// Notes on stable sorting:
|
||||
@ -204,6 +222,9 @@ func StringsAreSorted(x []string) bool { return IsSorted(StringSlice(x)) }
|
||||
//
|
||||
// It makes one call to data.Len to determine n, O(n*log(n)) calls to
|
||||
// data.Less and O(n*log(n)*log(n)) calls to data.Swap.
|
||||
//
|
||||
// Note: in many situations, the newer slices.SortStableFunc function is more
|
||||
// ergonomic and runs faster.
|
||||
func Stable(data Interface) {
|
||||
stable(data, data.Len())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user