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
fnmergeInPlace(
comptimeT: type,
items: []T,
A_arg: Range,
B_arg: Range,
context: anytype,
comptimelessThan: fn (@TypeOf(context), lhs: T, rhs: T) bool,
) void {
if (A_arg.length() == 0orB_arg.length() == 0) return;
// this just repeatedly binary searches into B and rotates A into position.// the paper suggests using the 'rotation-based Hwang and Lin algorithm' here,// but I decided to stick with this because it had better situational performance//// (Hwang and Lin is designed for merging subarrays of very different sizes,// but WikiSort almost always uses subarrays that are roughly the same size)//// normally this is incredibly suboptimal, but this function is only called// when none of the A or B blocks in any subarray contained 2√A unique values,// which places a hard limit on the number of times this will ACTUALLY need// to binary search and rotate.//// according to my analysis the worst case is √A rotations performed on √A items// once the constant factors are removed, which ends up being O(n)//// again, this is NOT a general-purpose solution – it only works well in this case!// kind of like how the O(n^2) insertion sort is used in some placesvarA = A_arg;
varB = B_arg;
while (true) {
// find the first place in B where the first item in A needs to be insertedconstmid = binaryFirst(T, items, items[A.start], B, context, lessThan);
// rotate A into placeconstamount = mid - A.end;
mem.rotate(T, items[A.start..mid], A.length());
if (B.end == mid) break;
// calculate the new A and B rangesB.start = mid;
A = Range.init(A.start + amount, B.start);
A.start = binaryLast(T, items, items[A.start], A, context, lessThan);
if (A.length() == 0) break;
}
}
merge operation without a buffer