This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Private Function
chosePivot
Private Function
std.sort.pdq.chosePivot
fnchosePivot(a: usize, b: usize, pivot: *usize, context: anytype) Hint
chooses a pivot in items[a..b]. swaps likely_sorted when items[a..b] seems to be already sorted.
fnchosePivot(a: usize, b: usize, pivot: *usize, context: anytype) Hint {
// minimum length for using the Tukey's ninther methodconstshortest_ninther = 50;
// max_swaps is the maximum number of swaps allowed in this functionconstmax_swaps = 4 * 3;
constlen = b - a;
consti = a + len / 4 * 1;
constj = a + len / 4 * 2;
constk = a + len / 4 * 3;
varswaps: usize = 0;
if (len >= 8) {
if (len >= shortest_ninther) {
// find medians in the neighborhoods of `i`, `j` and `k`sort3(i - 1, i, i + 1, &swaps, context);
sort3(j - 1, j, j + 1, &swaps, context);
sort3(k - 1, k, k + 1, &swaps, context);
}
// find the median among `i`, `j` and `k` and stores it in `j`sort3(i, j, k, &swaps, context);
}
pivot.* = j;
returnswitch (swaps) {
0 => .increasing,
max_swaps => .decreasing,
else => .unknown,
};
}
chooses a pivot in
items[a..b]. swaps likely_sorted whenitems[a..b]seems to be already sorted.