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):

  1. use hashmap of initial size n , load factor 1
  2. use arraylist of size n, store (key, value) pairs. implement get() method map

is there better way (maybe guava immutablemap)?

see perfect hash function

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.

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -