phelps.io

Class KeyStore

public class KeyStore extends Object

Store (key, data-offset) pairs. Keys are saved in a B-tree - like data structure, which can access very large key sets with minimal disk access and memory use. Keys are Unicode strings of any length, provided that three can fit into blocksize. The data associated with a key is a long (8 bytes), which is used by DiskHash as an offset into a DataStore. Nodes of the B-tree are read on demand and cached in memory in java.lang.ref.SoftReferences. Nodes written to are kept in memory and not written to disk until a flush or a close.

See Also: DiskHash DataStore

Field Summary
static intVERSION
Data format version.
Constructor Summary
KeyStore(String filename)
KeyStore(String filename, int blocksize)
Method Summary
voidclose()
voidflush()
longget(String key)
Return data offset for given key.
voidinsert(String key, long dataoffset)
Add key of given name and data offset to B-tree.
Iterator<String>iterator()
Iterator over keys, in sorted order.
Iterator<String>iterator(String key1, String key2)
Iterator over range from key1 to key2, inclusive.
voidremove(String key)
voidset(String key, long dataoffset)
Replace data offset for key.

Field Detail

VERSION

public static final int VERSION
Data format version.

Constructor Detail

KeyStore

public KeyStore(String filename)

KeyStore

public KeyStore(String filename, int blocksize)

Parameters: blocksize size of tree nodes, mimimum of 1K bytes. If KeyStore already exists, the passed value is ignored and the value is retrieved from its storage on disk.

Method Detail

close

public void close()

flush

public void flush()

get

public long get(String key)
Return data offset for given key. If no such key, return DiskHash.NO_RECORD.

insert

public void insert(String key, long dataoffset)
Add key of given name and data offset to B-tree. Key must not already exist.

iterator

public Iterator<String> iterator()
Iterator over keys, in sorted order.

iterator

public Iterator<String> iterator(String key1, String key2)
Iterator over range from key1 to key2, inclusive. If key1 is null, the first key in the store is used; if key2 is null, the last key in the store is used.

remove

public void remove(String key)

set

public void set(String key, long dataoffset)
Replace data offset for key. Key must already exist.