Suraj
Suraj

Reputation: 36547

Searching sorted doubles for inequalities in .net

Folks,

Given a set of sorted values (perhaps in a List<T>, SortedList<T,K>, etc.) what's the best way to go about evaluating inequalities (greater-than, less-than, greater-than-or-equal-to, less-than-or-equal-to a given value)? Possible with any of the standard .net types? Or easily coded up? Any pointers are greatly appreciated.

EDIT - of course I'm trying to make this as fast as possible. needs to be highly performant

Upvotes: 1

Views: 175

Answers (1)

digEmAll
digEmAll

Reputation: 57210

If you mean something like the good-old lower_bound/upper_bound functions on C++ map<>, AFAIK there's nothing built-in in C#.
On List<T> there's a BinarySearch method implemented, but it works on exact matching only.

Anyway, you can easily implement it by yourself, peraphs using the code in this question as an example:
Is there a Lower Bound function on a SortedList<K ,V>?

Upvotes: 2

Related Questions