feature. See also
. The project being documented here (as the example) is the Zig library itself.
block.findLastBackward
fn findLastBackward(
comptime T: type,
items: []T,
value: T,
range: Range,
unique: usize,
context: anytype,
comptime lessThan: fn (@TypeOf(context), lhs: T, rhs: T) bool,
) usize
File
Code
fn findLastBackward(
comptime T: type,
items: []T,
value: T,
range: Range,
unique: usize,
context: anytype,
comptime lessThan: fn (@TypeOf(context), lhs: T, rhs: T) bool,
) usize {
if (range.length() == 0) return range.start;
const skip = @max(range.length() / unique, @as(usize, 1));
var index = range.end - skip;
while (index > range.start and lessThan(context, value, items[index - 1])) : (index -= skip) {
if (index < range.start + skip) {
return binaryLast(T, items, value, Range.init(range.start, index), context, lessThan);
}
}
return binaryLast(T, items, value, Range.init(index, index + skip), context, lessThan);
}