From a sorted map, I want to retrieve a subset of n entries, starting m entries before a specified value v. For example, for the key set k = {0.2, 0.3, 0.4, 0.6, 0.8, 0.9, 1.0}, a query with n=5, m=2, v=0.5, would return {0.3, 0.4, 0.6, 0.8, 0.9}. Is there an implementation of a data structure in Java supporting such a query, without having to iterate over the whole (big) set?
What do I need this for? Interpolation. I want to interpolate at v based on the values in the map. However, I have many v. They are sorted, and have a spacing between them much smaller than the ones in k. So, I take a range of entries from the map, do some expensive preparatory calculations with them (for example calculating coefficients of a polynom), and can then quickly interpolate another value in that range (by evaluating the polynom with that value).
But why do I need the m entries before v? The values in k are usually equally spaced, and in order to avoid the Runge phenomenon of high oscillations at the ends of the interpolation interval, I simply cut them off, which means I need some nodes before the actual valid interval of the interpolation.
Does that make sense? What’s your suggestion?
(It would be fun if a method like java.util.TreeMap.ceilingEntry() would return an iterator, with which I could step back twice.)