View source code
Display the source code in std/algorithm/searching.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Function std.algorithm.searching.minCount
Prototype
Tuple!(ElementType!Range,size_t) minCount(alias pred, Range)( Range range ) if (isInputRange!Range && !isInfinite!Range && is(typeof(binaryFun!pred(range.front, range.front))));
Parameters
Name | Description |
---|---|
pred | The ordering predicate to use to determine the minimal element. |
range | The input range to count . |
Returns
The minimum element of a range
together with the number of
occurrences. The function can actually be used for counting the
maximum or any
other ordering predicate (that's why maxCount
is
not provided).
Example
import std.conv : text; debug(std_algorithm) scope(success) writeln("unittest @", __FILE__, ":", __LINE__, " done."); int[] a = [ 2, 3, 4, 1, 2, 4, 1, 1, 2 ]; // Minimum is 1 and occurs 3 times assert(minCount(a) == tuple(1, 3)); // Maximum is 4 and occurs 2 times assert(minCount!("a > b")(a) == tuple(4, 2));