authorgravatar for jahe788@gmail.comIntegratedQuantum <jahe788@gmail.com> 2023-05-17 17:20:21+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-17 18:26:49-07:00
log6e05620117e4bae98dc5fac2fbc1b81aa7ad17c4
tree42c924c4de0b0a4db03a431fec2192538a41c6c3
parentad20236e977cf6e55f2da1340952e521e2507786

Document the sorting order in `std.sort`.


1 files changed, 3 insertions(+), 0 deletions(-)

lib/std/sort.zig+3
...@@ -109,6 +109,7 @@ test "binarySearch" {...@@ -109,6 +109,7 @@ test "binarySearch" {
109109
110/// Stable in-place sort. O(n) best case, O(pow(n, 2)) worst case.110/// Stable in-place sort. O(n) best case, O(pow(n, 2)) worst case.
111/// O(1) memory (no allocator required).111/// O(1) memory (no allocator required).
112/// Sorts in ascending order with respect to the given `lessThan` function.
112/// This can be expressed in terms of `insertionSortContext` but the glue113/// This can be expressed in terms of `insertionSortContext` but the glue
113/// code is slightly longer than the direct implementation.114/// code is slightly longer than the direct implementation.
114pub fn insertionSort(115pub fn insertionSort(
...@@ -130,6 +131,7 @@ pub fn insertionSort(...@@ -130,6 +131,7 @@ pub fn insertionSort(
130131
131/// Stable in-place sort. O(n) best case, O(pow(n, 2)) worst case.132/// Stable in-place sort. O(n) best case, O(pow(n, 2)) worst case.
132/// O(1) memory (no allocator required).133/// O(1) memory (no allocator required).
134/// Sorts in ascending order with respect to the given `context.lessThan` function.
133pub fn insertionSortContext(len: usize, context: anytype) void {135pub fn insertionSortContext(len: usize, context: anytype) void {
134 var i: usize = 1;136 var i: usize = 1;
135 while (i < len) : (i += 1) {137 while (i < len) : (i += 1) {
...@@ -229,6 +231,7 @@ const Pull = struct {...@@ -229,6 +231,7 @@ const Pull = struct {
229231
230/// Stable in-place sort. O(n) best case, O(n*log(n)) worst case and average case.232/// Stable in-place sort. O(n) best case, O(n*log(n)) worst case and average case.
231/// O(1) memory (no allocator required).233/// O(1) memory (no allocator required).
234/// Sorts in ascending order with respect to the given `lessThan` function.
232/// Currently implemented as block sort.235/// Currently implemented as block sort.
233pub fn sort(236pub fn sort(
234 comptime T: type,237 comptime T: type,