From 5e59d6ebd110a7c19770c7d996930ff379ba5726 Mon Sep 17 00:00:00 2001 From: jiahua wang <wjh180909@gmail.com> Date: Wed, 22 Sep 2021 07:59:11 +0800 Subject: [PATCH] sort: improve sort documentation Fixes #48527 Change-Id: Ib5df0819cbcd5c2e4f03bda841871d237af96b19 Reviewed-on: https://go-review.googlesource.com/c/go/+/351336 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> --- src/sort/sort.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sort/sort.go b/src/sort/sort.go index cbaa8c3aac2..749310764af 100644 --- a/src/sort/sort.go +++ b/src/sort/sort.go @@ -223,7 +223,7 @@ func quickSort(data Interface, a, b, maxDepth int) { } } -// Sort sorts data. +// 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. func Sort(data Interface) { @@ -370,7 +370,8 @@ func StringsAreSorted(x []string) bool { return IsSorted(StringSlice(x)) } // - Often "optimal" algorithms are optimal in the number of assignments // but Interface has only Swap as operation. -// Stable sorts data while keeping the original order of equal elements. +// Stable sorts data in ascending order as determined by the Less method, +// while keeping the original order of equal elements. // // 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. -- GitLab