Jon Swanson wrote:So I broke that down into
a data structure containing
a dictionary keyed on (x,y)
regression coefficients
and methods to regress on (w,x,y)...
Whoa there. My advice: slow down and take things one at a time.
Let's look at the first: "a dictionary keyed on (x,y)":
Anything with a "key" in it suggests a java.util.Map.
The questions you then need to ask yourself are:
1. (Which you've already answered yourself) Do you need fast access to a specific x,y value?
2. Do the Map keys need to be
ordered? If so, you'll need a SortedMap.
3. Do you need to get ranges of values for x,y? If so, you'll probably need a NavigableMap.
In general, the fastest type of Map for direct access to a key is a HashMap, but it is
unordered, so if the answer to either 2 or 3 is true, the normal choice is a TreeMap, although there is also ConcurrentSkipListMap.
The only other wrinkle you need to consider is this: Do you need
more than one value to be stored for any given key? If so, then each key needs to be associated with a java.util.Collection of some sort. If duplicate values are allowed for any given key, this should probably be a java.util.List; if not, it should be a java.util.Set.
It might also be worth mentioning that
Java already has a class that does some of what you want, called
Point2D.Double, so you could either extend it for your DataPoint class or (possibly better) have your class
include one. The nice thing about this is that the
equals() and
hashCode() methods (which you'll need if you want to put your DataPoint in a HashMap) are already defined, so you don't have to write them again.
HIH
Winston