net.handle.jdb
Class RO_DBHash

java.lang.Object
  extended by net.handle.jdb.RO_DBHash

public class RO_DBHash
extends java.lang.Object

Object used to store key/value pairs in a fast, persistent index. Uses a hashing algorithm (with configurable hash size) to locate records in the file quickly, and a memory cache (also with configurable size) to speed up access to heavily used records. Potential improvement: Currently the memory cache for is rather crude. If the cache gets over the configured size, *all* items are removed. It would probably be better if there were some sort of least-recently used algorithm or something. It may also be good to purge the cache asynchronously.


  BC_REC_START Block Format:
  -----------------------------------------------------
  | Block Code == BC_REC_START (1 byte)               |
  | Key Length (4 bytes)                              |
  | Data Length (4 bytes)                             |
  | Next Record Ptr (8 bytes)                         |
  | [ Cont. Block Ptr (8 bytes)                       |
  |     if ((KeyLen+DataLen) > (BlockSz-HeaderSz)) ]  |
  | Data (BlockSz-HeaderSz bytes)                     |
  | ...                                               |
  -----------------------------------------------------

  BC_REC_CONT Block Format:
  -----------------------------------------------------
  | Block Code == BC_REC_CONT (1 byte)                |
  | Remainder Length (4 bytes)                        |
  | [ Cont. Block Ptr (8 bytes)                       |
  |     if this is not the last continuation block ]  |
  | Data                                              |
  | ...                                               |
  -----------------------------------------------------

  BC_REC_UNUSED Block Format:
  -----------------------------------------------------
  | Block Code == BC_REC_UNUSED (1 byte)              |
  | Anything.  (BlockSz-1 bytes)                      |
  -----------------------------------------------------

 TODO:
  Create pack() method to compress file
 


Field Summary
 boolean DEBUG
           
static java.lang.String V1_FILE_ID
           
 
Constructor Summary
RO_DBHash(java.io.File hashFile, int hashLength, int cacheSize)
          Create/open a hashed index file with a hashtable of hashLength entries and a cache with a maximum of cacheSize records.
 
Method Summary
 void close()
          Close the random-access file.
 void dumpDataStructure(java.io.PrintStream out)
          Dump a human-readable display of all of the records in the table and cache.
 void dumpDepthGraph()
          Display a crude text-based graph of the hash distribution.
 void dumpRecords(java.io.PrintStream out)
          Dump all of the records in the table in hexadecimal format with the keys separated from the values by a colon.
 java.util.Enumeration getEnumerator()
          Return an enumeration used to iterate over all of the records in the table.
 byte[] getValue(byte[] key)
          Get the data value associated with the specified key.
static void main(java.lang.String[] argv)
          Main routine
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

V1_FILE_ID

public static final java.lang.String V1_FILE_ID
See Also:
Constant Field Values

DEBUG

public boolean DEBUG
Constructor Detail

RO_DBHash

public RO_DBHash(java.io.File hashFile,
                 int hashLength,
                 int cacheSize)
          throws java.lang.Exception
Create/open a hashed index file with a hashtable of hashLength entries and a cache with a maximum of cacheSize records.

Throws:
java.lang.Exception
Method Detail

close

public void close()
           throws java.lang.Exception
Close the random-access file.

Throws:
java.lang.Exception

getValue

public final byte[] getValue(byte[] key)
                      throws java.lang.Exception
Get the data value associated with the specified key.

Returns:
null if the specified key does not exist.
Throws:
java.lang.Exception

dumpDepthGraph

public void dumpDepthGraph()
                    throws java.lang.Exception
Display a crude text-based graph of the hash distribution.

Throws:
java.lang.Exception

dumpRecords

public void dumpRecords(java.io.PrintStream out)
Dump all of the records in the table in hexadecimal format with the keys separated from the values by a colon.


getEnumerator

public java.util.Enumeration getEnumerator()
Return an enumeration used to iterate over all of the records in the table.


dumpDataStructure

public void dumpDataStructure(java.io.PrintStream out)
Dump a human-readable display of all of the records in the table and cache.


main

public static void main(java.lang.String[] argv)
                 throws java.lang.Exception
Main routine

Throws:
java.lang.Exception