Re: 2D lookup table
Mize-ze wrote On 01/31/07 12:16,:
If I want to store and fetch information from a matrix like structure
where the indexes of the matrix are not integers but other data
structures, how such thing can be done without a translation table?
Example:
If I have a list of doubles and I want to store a value per each pairs
of values
What is the best way to do this?
I don't know of any standard class(es) to do this. You
could use a HashMap, but if the values you search for are
even the teensiest bit different from those you inserted,
you won't find them. That is, if the matrix has an entry
for (1.0,2.0) but the calculations that produce the search
pair produce (1.00000000000000021,1.99999999999999987), the
tiny numerical errors will cause the search to come up empty.
You need (I think) some kind of "proximity search" or
"nearest match" search that will be insensitive to the small
inaccuracies that creep into floating-point calculations. A
binary tree might work, comparing X coordinates on the even
levels and Y coordinates on the odds, and searching both
branches if the target value is "very close" to the tree's
dividing value.
Or perhaps what you need is interpolation in a mesh?
Best bet there, I think, is to search each coordinate axis
to find the two values that bracket the search coordinate,
pluck out the four "corner" values, and interpolate in that
rectangular patch. Again, I don't think Java supplies any
built-in class for the job.
--
Eric.Sosman@sun.com