 | binarySearchBinarySearch Method (FuncInt32, Int32, NullableInt32, NullableInt32, Int32) |
Performs a binary search on a discrete range from min to max (exclusive). Returns the number for which searcher returns 0.
Namespace:
WhetStone.Looping
Assembly:
WhetStone (in WhetStone.dll) Version: 1.0.4.0 (1.0.0.0)
Syntaxpublic static int BinarySearch(
Func<int, int> searcher,
Nullable<int> min = null,
Nullable<int> max = null,
int failvalue = -1
)
Parameters
- searcher
- Type: SystemFuncInt32, Int32
The searcher function, a positive number means the input is too high, a negative number means the input is too low, zero means the input has been found. - 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.
Return Value
Type:
Int32The index on which
searcher returned zero, or
failvalue if such is not found.
RemarksIn case both min and max are set to , index 0 will be tested, and an exponential search will be done with zero being either an upper or lower bound.
See Also