Search code examples
.netc5

How to search C5.TreeSet?


I have a C5.TreeSet<double>, a sorted data structure. https://github.com/sestoft/C5/

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


Solution

  • 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.