which is the best way to write a bidimensional hashmap efficiently in Java? Just to give an example of what I’m talking about: I’m developing some algorithms related to collective intelligence, these algorithms works by calculating correlation between pairs of elements..
Without caching these values, since they are calculated on same pairs multiple times, performance are horrible.. (algorithms can be O(n^2) but maybe O(n^3) so I was thinking about using an HashMap to store values to be used multiple times.
Which is the most efficient way to implement such a data structure in Java? It should be possble to cache and remove a value generated by a pair of elements with O(1), but using an explicit class seems too heavy anyway.
If Java will turn out to be not enough I’ll have to switch to C/C++, so any idea related to these languages are welcome too.
Thanks
I partially solved the problem by concatenating hashcodes of both items using something like this:
I still have to figure out which is the most efficient way to store all the elements already cached with a specified one to remove them when the algorithm don’t need the item anymore, just to avoid filling of the
HashMapwith a waste of item. That’s because the kind of algorithm merges two items at every iteration removing them from used ones but adding the new generated item.