range : Java Glossary

range
A range is a pair of numbers, a low and high bound. Java and programmers in general pay little attention to them. Logically every variable should have an associated low and high bound and all data entry should assure the value falls in range. Often you have a set of ranges, and you want to find which band a number falls in e.g.

Techniques for searching a list of ranges to find the one a given values falls in:

Often your ranges are all the same length. Then you can find the slot by dividing your value by the range length. This is very fast.

If the length of each range is a multiple of some unit, you can construct a lookup table. You take your value, divide by the length of the unit, and use it to index the table to give you the band number. This is very fast. This technique can be used to deal with weighted values that behave like extending the length of the associated band.

If your ranges are short, and sparse, you can index the start point, rounded, in a HashMap or TreeMap. There is no built-in Collection that will look up ranges for you. You must roll your own.


CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/range.html J:\mindprod\jgloss\range.html
logo
Please email your , letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email. If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, please quote it and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. Threatening to kill me or spouting obscenities has yet to persuade me to change my mind.
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.179.212]
You are visitor number 11.