A couple of months ago, in this
thread:
https://coderanch.com/t/617504/java/java/Working-HashMaps-Compressed-Matrix
the best working solution given there was to use a HashMap<Point, Integer>.
Now, there's nothing wrong with that, of course, but I kept the feeling that this was a bit of a waste .
Surely, if we have a class like this, for example:
then all we need is a HashSet/TreeSet<PietsPoint>(), saving on the Integer.
But I ran into a problem that I could only partially solve. The question is: given a Point p,
how to retrieve the associated PietsPoint? The idea is that some x, y values are given, and
I have to update the count. But, as far as I know, there is no 'get()' method defined for a
set, other than using some iterator. But the use of an iterator would be unacceptably slow.
I need some direct access.
For a TreeSet, I got it sort-of working, by (when having an x,y pair given) using:
And that worked, but it turned out to be about 60% slower than the HashMap-solution.
But for a HashSet, I was unable to find a solution, so I do not know if a HashSet would
turn out to be faster and/or more economical on memory useage.
I am currently working on a problem, where I have to use a similar structure. Therefore my question:
Anyone an idea on using a HashSet?
Greetz,
Piet