Searching numerous ranges without using a linear search

Hello,

Hope this is the correct forum for this question:

I am putting a database table into a hashmap, and the table columns are set up as such:

5 digit number, lower bound, upper bound, other data

The key is composite made up of the 5 digit number(5dn), and lower bound since there can be multiple ranges for a given 5dn.

With a known value associated for a given 5dn I need to search through all of the ranges related to the 5dn and determine which range the known value falls into.

Is there a way to sift through all of these ranges without performing a linear search? Can I set up a hash map using some key? Speed and efficiency is a priority, but is it possible with how the table is set up? THanks!

[747 byte] By [AndrewJB444a] at [2007-10-1 23:57:32]
# 1
The best way of doing this is probably in SQL. However, if you insist on doing it with a HashMap, I'd suggest making the key of the map be the 5dn, and the value be a list of entries sorted by lower bound. Then you can do binary chop on the list.
YAT_Archivista at 2007-7-15 15:50:07 > top of Java-index,Core,Core APIs...