0

I need a map, and in the map I need a range with a key:

For example

Map<Range,Value> name;

where Range can be

for example values between 0 - 600, the other range can be 601 - 900, ...

And for example if I need name.containsKey(480) I need true because is in the first range, And If I need the value name.get(780) I need the value in the range 601-900

I don't know what is the best dataType to do it.

Thanks a lot.

Code Geas Coder
  • 1,839
  • 4
  • 23
  • 29
  • 2
    Are there any gaps between ranges? If not, you can use a `TreeMap`. Otherwise, consider Guava's [`RangeMap`](https://google.github.io/guava/releases/snapshot/api/docs/com/google/common/collect/RangeMap.html). – shmosel Jun 26 '18 at 23:31
  • Can ranges overlap? – lexicore Jun 26 '18 at 23:33
  • `contains` relies on the relationship of the `hashCode` of the objects, so I doubt theres' a "simple" solution based on the current implementation – MadProgrammer Jun 26 '18 at 23:40
  • @MadProgrammer *`contains` relies on the relationship of the `hashCode` of the objects* - if hash tables are based on hash codes, this does not mean everything else must be based on hash code as well. Nothing obliges `Map` implementations to use hash codes. – lexicore Jun 26 '18 at 23:46
  • @lexicore Sorry, took the meaning to literally – MadProgrammer Jun 26 '18 at 23:57
  • Not The Ranges are not overlapping – Code Geas Coder Jun 27 '18 at 14:22

0 Answers0