feature. See also
. The project being documented here (as the example) is the Zig library itself.
block.mergeInternal
fn mergeInternal(
comptime T: type,
items: []T,
A: Range,
B: Range,
buffer: Range,
context: anytype,
comptime lessThan: fn (@TypeOf(context), lhs: T, rhs: T) bool,
) void
File
Code
fn mergeInternal(
comptime T: type,
items: []T,
A: Range,
B: Range,
buffer: Range,
context: anytype,
comptime lessThan: fn (@TypeOf(context), lhs: T, rhs: T) bool,
) void {
// when this algorithm is finished, 'buffer' will contain its original contents, but in a different order
var A_count: usize = 0;
var B_count: usize = 0;
var insert: usize = 0;
if (B.length() > 0 and A.length() > 0) {
while (true) {
if (!lessThan(context, items[B.start + B_count], items[buffer.start + A_count])) {
mem.swap(T, &items[A.start + insert], &items[buffer.start + A_count]);
A_count += 1;
insert += 1;
if (A_count >= A.length()) break;
} else {
mem.swap(T, &items[A.start + insert], &items[B.start + B_count]);
B_count += 1;
insert += 1;
if (B_count >= B.length()) break;
}
}
}
blockSwap(T, items, buffer.start + A_count, A.start + insert, A.length() - A_count);
}