For ages I've wanted a persistent, disk-based, implementation of a Map. I finally found jdbm which is a persisent, disk-based, BTree. I wrote a PersistentMap which delegates to JDBM.


PersistentMap implements Map, and provides 4 methods beyond what Map needs:

    import com.tropo.persist.*;
    PersistentMap pm = new PersistentMap( "zip"); // 'zip' is base of file name, def key is String
    pm.put( "one", "A"); // pm is-a Map
    pm.put( "two", "AB");
    pm.put( "three", "ABC");
    pm.commit(); // there are a few additional methods such as commit() (flush to disk), close(), and setFlushFreq (for periodic writes to disk)
    PersistentMap pm2 = new PersistentMap( "zip"); // now pm2 has the same contents as pm

Download - source code to PersistentMap and PersistentMapTestCase


junit - for the test case
JISP an alternative to JDBM which I have not used.

Future Directions

I may continue to enhance this and also expose a PersistentList and PersistentSet if these become useful and if the next stable release of JDBM is missing such classes. I'll also expose javadoc and doc more if necessary.