 | binarySearchBinarySearch Method (FuncInt32, Boolean, NullableInt32, NullableInt32, Int32, binarySearchBooleanBinSearchStyle) |
Performs a binary search on a discrete range from min to max (exclusive). Returns the number for which searcher returns either the first or last in the range, depending on the style.
Namespace:
WhetStone.Looping
Assembly:
WhetStone (in WhetStone.dll) Version: 1.0.4.0 (1.0.0.0)
Syntaxpublic static int BinarySearch(
Func<int, bool> searcher,
Nullable<int> min = null,
Nullable<int> max = null,
int failvalue = -1,
binarySearchBooleanBinSearchStyle style = binarySearchBooleanBinSearchStyle.GetLastTrue
)
Parameters
- searcher
- Type: SystemFuncInt32, Boolean
A searcher function. - min (Optional)
- Type: SystemNullableInt32
The minimum of the range to search in (inclusive). Setting this to will perform an exponential search. - max (Optional)
- Type: SystemNullableInt32
The maximum of the range to search in (exclusive). Setting this to will perform an exponential search. - failvalue (Optional)
- Type: SystemInt32
The value to return if no correct index is found. - style (Optional)
- Type: WhetStone.LoopingbinarySearchBooleanBinSearchStyle
The boolean search style, whether to return the index of the first or last .
Return Value
Type:
Int32The index on which
searcher returned the first or last
, or
failvalue if such is not found.
RemarksFor every "normal" binary search call, the searcher will be called twice.
Any exception thrown by the searcher will be treated as a output.
See Also