Zig 0.17.0-dev (Split by item) 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.
std › sort › block › findLastBackward Private Function findLastBackward Doc Source Private Function std.sort.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 Params T : type items : []T value : T range : Range unique : usize context lessThan : fn (@TypeOf (context ), lhs : T , rhs : T ) bool File sort/block.zig: 917
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937 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 );
}