sestoft / C5

C5 generic collection library for C#/.NET
http://www.itu.dk/research/c5/
MIT License
1.03k stars 181 forks source link

How to search TreeSet? #35

Closed hickford closed 9 years ago

hickford commented 9 years ago

I have a C5.TreeSet<double>

Given a value x, I'd like to search the set S for the greatest index i such S[j] <= x for all j ≤ i (similar to Python's bisect.bisect). How can I do that?

I was previously using List<T> with BinarySearch

Reproduced from http://stackoverflow.com/questions/30624322/how-to-search-c5-treeset

hickford commented 9 years ago

When S is a TreeSet, or more generally, an IIndexedSorted, then S.CountTo(x) will give you the number of items strictly less than x.