argMax
Function parameters
Parameters
- T:type
- items:[]const T
- context:anytype
- lessThan:fn (context: @TypeOf(context), lhs: T, rhs: T) bool
Type definitions in this namespace
Types
Functions in this namespace
Functions
- insertion
- Stable in-place sort.
- insertionContext
- Stable in-place sort.
- heap
- Unstable in-place sort.
- heapContext
- Unstable in-place sort.
- asc
- Use to generate a comparator function for a given type.
- desc
- Use to generate a comparator function for a given type.
- binarySearch
- Returns the index of an element in `items` returning `.eq` when given to `compareFn`.
- lowerBound
- Returns the index of the first element in `items` that is greater than or equal to `context`,
- upperBound
- Returns the index of the first element in `items` that is greater than `context`, as determined
- partitionPoint
- Returns the index of the partition point of `items` in relation to the given predicate.
- equalRange
- Returns a tuple of the lower and upper indices in `items` between which all
Source
Implementation
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;
}