]> Cypherpunks.ru repositories - gostls13.git/commitdiff
sort: comments directing new code to use the slices package when applicable
authorEli Bendersky <eliben@golang.org>
Mon, 12 Jun 2023 16:00:26 +0000 (09:00 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 13 Jun 2023 18:07:00 +0000 (18:07 +0000)
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>
src/sort/sort.go

index 68e2f0d082f181e4753d9b559893bbb9ace8f2ab..1760e12c25621b596f22d51376fc29aa5ff35e97 100644 (file)
@@ -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())
 }