Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the most memory efficient method of storing a large number of Strings in a map?

I want to store huge amounts of Strings in a Map<String, MagicObject>, so that the MagicObjects can be accessed quickly. There are so many entries to this Map that memory is becoming a bottleneck. Assuming the MagicObjects can't be optimized, what is the most efficient type of map I could use for this situation? I am currently using the following:

gnu.trove.map.hash.TCustomHashMap<byte[], MagicObject>
like image 817
Andreas Hartmann Avatar asked Jun 15 '16 14:06

Andreas Hartmann


1 Answers

If your keys are long enough and have a lot of long enough common prefixes then you can save memory by using a trie (prefix tree) data structure. Answers to this question point to a a couple of Java implementations of trie.

like image 127
Leon Avatar answered Oct 24 '22 00:10

Leon