feature. See also
. The project being documented here (as the example) is the Zig library itself.
block.mergeExternal
fn mergeExternal(
comptime T: type,
items: []T,
A: Range,
B: Range,
cache: []T,
context: anytype,
comptime lessThan: fn (@TypeOf(context), lhs: T, rhs: T) bool,
) void
File
Code
fn mergeExternal(
comptime T: type,
items: []T,
A: Range,
B: Range,
cache: []T,
context: anytype,
comptime lessThan: fn (@TypeOf(context), lhs: T, rhs: T) bool,
) void {
var A_index: usize = 0;
var B_index: usize = B.start;
var insert_index: usize = A.start;
const A_last = A.length();
const B_last = B.end;
if (B.length() > 0 and A.length() > 0) {
while (true) {
if (!lessThan(context, items[B_index], cache[A_index])) {
items[insert_index] = cache[A_index];
A_index += 1;
insert_index += 1;
if (A_index == A_last) break;
} else {
items[insert_index] = items[B_index];
B_index += 1;
insert_index += 1;
if (B_index == B_last) break;
}
}
}
const cache_a = cache[A_index..A_last];
@memcpy(items[insert_index..][0..cache_a.len], cache_a);
}