I have some sorted data which has the starting and ending integers of each range, and they are contiguous. So my data might look like this:
Number Start End
0 0 47
1 48 94
2 95 287
3 288 1123
and so on.
I will get an integer like 113
and I want the fastest way to search the data to find the matching number. I can afford to stick the data into some structure that optimizes the retrieval / comparison speed.
My data is very large.
EDIT: I chose an answer, and this is the code I ended up with:
Public Function EndingCaptureNumber(CaptureEnd As Integer) As Integer
EndingCaptureNumber = CaptureEnds.BinarySearch(CaptureEnd)
If EndingCaptureNumber < 0 Then
Return (Not EndingCaptureNumber) - 1
End If
End Function
Capture ends is a list of the end of each range. Not is the bitwise compliment. Since this finds the first that was greater, I subtract 1 to get the last that was not greater.
Edit: Duplicate Question Rebuttal
The answer that came out of this uses the built in BinarySearch but handles values that are not an exact match. Seekers reading that other article would not learn this (imho) better answer. Plus, the other question is cluttered by the actual data types the OP used in his RL problem.