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(log n), I expect the number of elements returned to be small. Using take-while and drop-while would let me exit once…