I have a number of coordinate spaces measuring 65,536 by 65,536 and populated by many objects where no two can share the same coordinates. Given this, I can guarantee a unique hash for each object by combining the two shorts that make the coordinates into int which makes the hash.
To store references to these objects I am currently using a HashMap with a custom immutable Point class as key. However since I am beginning to utilise a whole lot of these coordinate spaces at once I have begun to look at ways to trim down on memory usage.
My understanding of how java's HashMap works is basic, but considering that I can guarantee a unique hash for each object, it seems like I could be using a much more memory efficient version which:
- Doesn't use buckets which can contain multiple objects
- Can put and get objects by using the hash instead of using a key
Does such a HashMap-like collection exist?
edit: The coordinate spaces are sparse, running at around 2000-3000 objects per.