Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are they any decent on-disk implementations of Java's Map?

I'm looking for an on-disk implementation of java.util.Map. Nothing too fancy, just something that I can point at a directory or file and have it store its contents there, in some way it chooses. Does anyone know of such a thing?

like image 242
jjujuma Avatar asked Jan 27 '11 11:01

jjujuma


People also ask

What is the most commonly used implementation of the Map interface?

HashMap Class The most common class that implements the Java Map interface is the HashMap. It is a hash table based implementation of the Map interface. It implements all of the Map operations and allows null values and one null key.

Which of the Map implementation is faster and why?

HashMap will generally be fastest, since it has the best cache behavior ( HashMap iterates directly over the backing array, whereas TreeMap and LinkedHashMap iterate over linked data structures).

Which Map is best in Java?

There is no standard small implementation of Map in Java. HashMap is one of the best and most flexible Map implementations around, and is hard to beat.

Does Java Map implement collection?

Java has Iterable interface which is extended by Collection . The Collection is further extended by List , Queue and Set which has their different-different implementations but the unique thing notice is that the Map interface doesn't extend Collection interface.


2 Answers

You could have a look at the Disk-Backed-map project.

A library that implements a disk backed map in Java

A small library that provide a disk backed map implementation for storing large number of key value pairs. The map implementations (HashMap, HashTable) max out around 3-4Million keys/GB of memory for very simple key/value pairs and in most cases the limit is much lower. DiskBacked map on the other hand can store betweeen 16Million (64bit JVM) to 20Million(32bit JVM) keys/GB, regardless the size of the key/value pairs.

like image 90
aioobe Avatar answered Oct 28 '22 09:10

aioobe


If you are looking for key-object based structures to persist data then NoSQL databases are a very good choice. You'll find that some of them such MongoDB or Redis scale and perform for big datasets and apart from hash based look ups they provide interesting query and transactional features.

In essence these types of systems are a Map implementation. And it shouldn't be too complicated to implement your own adapter that implements java.util.Map to bridge them.

like image 41
Manuel Salvadores Avatar answered Oct 28 '22 09:10

Manuel Salvadores