java - How to save space with maps -
i have store large amounts of data in maps , total size critical. number of maps high, size of each individual map small (<10 mappings of them) , maps not change after creation.
i see 2 ways (let's assume know n mappings stored):
- use
hashmap
of initial size n , load factor 1 - use
arraylist
of size n, store (key, value) pairs. implementget()
method map
is there better way (maybe guava immutablemap
)?
for map no longer keys added, 1 go optimized hash function: array small feasible, , collisions minimal influence.
besides academical treatises out there, hash function can build n different smaller functions/value entities, , optimal can found trying combination on data set. , varying array sizes.
as area broad (like rehashing), search further, or yourself.
if have gotten many values, taking same object instance instead of having many different objects equal. done identity map map<t, t>
using first put key.
- a treemap large data inefficient linkedlist w.r.t. arraylist.
- the implementation of hashmap quite interesting efficiency. @ end 1 same
arraylist.trimtosize()
though irrelevant.