How do I get the sequence of numbers in a sorted-set that are between two integers in clojure?
- by Greg Rogers
Say I have a sorted-set of integers, xs, and I want to retrieve all the integers in xs that are [x, y), ie. between x and y.
I can do:
(select #(and (>= % x) (< % y)) xs)
But this is inefficient - O(n) when it could be O(k log n) where k is the number of integers returned.
I am just learning clojure so here is how I would do it in C++:
…