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 › argMax Public Function argMax Doc Source Public Function std.sort.argMax
pub fn argMax (
comptime T : type ,
items : []const T ,
context : anytype ,
comptime lessThan : fn (context : @TypeOf (context ), lhs : T , rhs : T ) bool ,
) ?usize Params T : type items : []const T context lessThan : fn (context : @TypeOf (context ), lhs : T , rhs : T ) bool File sort.zig: 898
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918 pub fn argMax (
comptime T : type ,
items : []const T ,
context : anytype ,
comptime lessThan : fn (context : @TypeOf (context ), lhs : T , rhs : T ) bool ,
) ?usize {
if (items .len == 0 ) {
return null ;
}
var biggest = items [0 ];
var biggest_index : usize = 0 ;
for (items [1 ..], 0 ..) |item , i | {
if (lessThan (context , biggest , item )) {
biggest = item ;
biggest_index = i + 1 ;
}
}
return biggest_index ;
}