Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disk based HashMap

Does Java have (or is there a library available) that allows me to have a disk based HashMap? It doesn't need to be atomic or anything, but it will be accessed via multiple threads and shouldn't crash if two are accessing the same element at the same time.

Anyone know of anything?

like image 458
synic Avatar asked Apr 16 '10 16:04

synic


People also ask

Which is better TreeMap or HashMap?

Conclusions. HashMap is a general purpose Map implementation. It provides a performance of O(1) , while TreeMap provides a performance of O(log(n)) to add, search, and remove items. Hence, HashMap is usually faster.

Which is faster set or HashMap?

HashMap is faster than HashSet because the values are associated to a unique key. In HashSet , member object is used for calculating hashcode value which can be same for two objects so equals() method is used to check for equality.

Is HashMap space efficient?

Besides that, hashmaps are less space efficient than arrays because they always have a load factor which is smaller than one, which is the same as saying that they keep more entries allocated than necessary due to the way they work.


2 Answers

MapDB

MapDB provides concurrent TreeMap and HashMap backed by disk storage or off-heap-memory. It is a fast, scalable and easy to use embedded Java database engine. It is packed with features such as transactions, space efficient serialization, instance cache and transparent compression/encryption. It also has outstanding performance rivaled only by native embedded db engines.

http://www.mapdb.org/

jdbm2

Embedded Key Value Java database.

https://code.google.com/p/jdbm2/

like image 123
Quartz Avatar answered Sep 24 '22 20:09

Quartz


Either properties files or Berkeley DB might be what you're looking for. The java.util.Properties itself implements java.util.Map and provides methods to load from and store to a file. The Berkeley DB is often been recommended as a lightweight key-value pair datastore.

like image 42
BalusC Avatar answered Sep 25 '22 20:09

BalusC