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(
3434
3535/// Stable in-place sort. O(n) best case, O(pow(n, 2)) worst case.
3636/// 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`.
3840pub fn insertionContext(a: usize, b: usize, context: anytype) void {
3941 assert(a <= b);
4042
......@@ -73,7 +75,9 @@ pub fn heap(
7375
7476/// Unstable in-place sort. O(n*log(n)) best case, worst case and average case.
7577/// 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`.
7781pub fn heapContext(a: usize, b: usize, context: anytype) void {
7882 assert(a <= b);
7983 // build the heap in linear time.
lib/std/sort/pdq.zig+3-2
......@@ -37,8 +37,9 @@ const Hint = enum {
3737
3838/// Unstable in-place sort. O(n) best case, O(n*log(n)) worst case and average case.
3939/// O(log(n)) memory (no allocator required).
40///
41/// Sorts in ascending order with respect to the given `lessThan` function.
40/// `context` must have methods `swap` and `lessThan`,
41/// which each take 2 `usize` parameters indicating the index of an item.
42/// Sorts in ascending order with respect to `lessThan`.
4243pub fn pdqContext(a: usize, b: usize, context: anytype) void {
4344 // slices of up to this length get sorted using insertion sort.
4445 const max_insertion = 24;