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