I have a List<KeyValuePair<double, double>>
, the list is sorted by KeyValuePair.Key
, so it's amendable to binary search. And I have a double
object. Now, my task is to find the index of the double
object. Here are the conditions that apply:
- If that
double
object matches one of theKeyValuePair.Key
within a specified tolerance, then the correspondingKeyValuePair.Value
should be returned. - If the
double
object falls outside the max and min range ofKeyValuePair.Key
, then a 0 should be returned. - If the
double
object falls within the max min of theKeyValuePair.Key
, but not matched any of theKeyValuePair.Key
within a specified tolerance, then the get the average of the nearest upper and nearest lowerKeyValuePair.Value
( as measured byKeyValuePair.Key
).
I know that a binary search implementation is available in C#, but it is not exactly suited to my needs. I would like to ask is there any implementation out there that already meets my needs? I don't want to spend a few hours writing and debugging the code that other people has already written, debugged and perfected.