I am trying to find a data structure that takes in a particular value from a range of values and map it to a key.
For example, I have the following conditions:
Guava RangeMap provides specialized solution out of the box:
RangeMap rangeMap = TreeRangeMap.create();
rangeMap.put(Range.closed(1, 100), "foo"); // {[1, 100] => "foo"}
rangeMap.put(Range.open(3, 6), "bar"); // {[1, 3] => "foo", (3, 6) => "bar", [6, 100] => "foo"}
rangeMap.get(42); // returns "foo"