authorgravatar for yujiri@disroot.orgyujiri8 <yujiri@disroot.org> 2023-06-27 03:51:06-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-06-27 00:51:06-07:00
logdae516dbdffaf771e072679a76a6d48f3f0aa182
treed4ccd739a0723c844cbb854dc3f82160b8f6b239
parentd881d841ed85808e59c20db6a25b019ab2e019f8
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

improve documentation of std.sort.*Context functions (#16145)


2 files changed, 9 insertions(+), 4 deletions(-)

lib/std/sort.zig+6-2
...@@ -34,7 +34,9 @@ pub fn insertion(...@@ -34,7 +34,9 @@ pub fn insertion(
3434
35/// Stable in-place sort. O(n) best case, O(pow(n, 2)) worst case.35/// Stable in-place sort. O(n) best case, O(pow(n, 2)) worst case.
36/// O(1) memory (no allocator required).36/// O(1) memory (no allocator required).
37/// Sorts in ascending order with respect to the given `lessThan` function.37/// `context` must have methods `swap` and `lessThan`,
38/// which each take 2 `usize` parameters indicating the index of an item.
39/// Sorts in ascending order with respect to `lessThan`.
38pub fn insertionContext(a: usize, b: usize, context: anytype) void {40pub fn insertionContext(a: usize, b: usize, context: anytype) void {
39 assert(a <= b);41 assert(a <= b);
4042
...@@ -73,7 +75,9 @@ pub fn heap(...@@ -73,7 +75,9 @@ pub fn heap(
7375
74/// Unstable in-place sort. O(n*log(n)) best case, worst case and average case.76/// Unstable in-place sort. O(n*log(n)) best case, worst case and average case.
75/// O(1) memory (no allocator required).77/// O(1) memory (no allocator required).
76/// Sorts in ascending order with respect to the given `lessThan` function.78/// `context` must have methods `swap` and `lessThan`,
79/// which each take 2 `usize` parameters indicating the index of an item.
80/// Sorts in ascending order with respect to `lessThan`.
77pub fn heapContext(a: usize, b: usize, context: anytype) void {81pub fn heapContext(a: usize, b: usize, context: anytype) void {
78 assert(a <= b);82 assert(a <= b);
79 // build the heap in linear time.83 // build the heap in linear time.
lib/std/sort/pdq.zig+3-2
...@@ -37,8 +37,9 @@ const Hint = enum {...@@ -37,8 +37,9 @@ const Hint = enum {
3737
38/// Unstable in-place sort. O(n) best case, O(n*log(n)) worst case and average case.38/// Unstable in-place sort. O(n) best case, O(n*log(n)) worst case and average case.
39/// O(log(n)) memory (no allocator required).39/// O(log(n)) memory (no allocator required).
40///40/// `context` must have methods `swap` and `lessThan`,
41/// Sorts in ascending order with respect to the given `lessThan` function.41/// which each take 2 `usize` parameters indicating the index of an item.
42/// Sorts in ascending order with respect to `lessThan`.
42pub fn pdqContext(a: usize, b: usize, context: anytype) void {43pub fn pdqContext(a: usize, b: usize, context: anytype) void {
43 // slices of up to this length get sorted using insertion sort.44 // slices of up to this length get sorted using insertion sort.
44 const max_insertion = 24;45 const max_insertion = 24;