All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class Acme.Dbz

java.lang.Object
   |
   +----java.util.Dictionary
           |
           +----Acme.Dbz

public class Dbz
extends Dictionary
Access a Unix DBZ file.

DBZ files are similar to DBM files. From the Java point of view, they are just on-disk hash tables. Comments from the C version:

The dbz database exploits the fact that when news stores a tuple, the `value' part is a seek offset into a text file, pointing to a copy of the `key' part. This avoids the need to store a copy of the key in the dbz files. However, the text file *must* exist and be consistent with the dbz files, or things will fail.

The basic format of the database is a simple hash table containing the values. A value is stored by indexing into the table using a hash value computed from the key; collisions are resolved by linear probing (just search forward for an empty slot, wrapping around to the beginning of the table if necessary). Linear probing is a performance disaster when the table starts to get full, so a complication is introduced. The database is actually one *or more* tables, stored sequentially in the .pag file, and the length of linear-probe sequences is limited. The search (for an existing item or an empty slot) always starts in the first table, and whenever MAXRUN probes have been done in table N, probing continues in table N+1. This behaves reasonably well even in cases of massive overflow. There are some other small complications added, see comments below.

The table size is fixed for any particular database, but is determined dynamically when a database is rebuilt. The strategy is to try to pick the size so the first table will be no more than 2/3 full, that being slightly before the point where performance starts to degrade. (It is desirable to be a bit conservative because the overflow strategy tends to produce files with holes in them, which is a nuisance.)

Fetch the software.
Fetch the entire Acme package.


Constructor Index

 o Dbz(File)
Constructor.

Method Index

 o dbmclose()
Close a database.
 o dbzcancel()
Cancel writing of in-core data.
 o dbzincore(boolean)
Control attempts to keep .pag file in core.
 o dbzsize(int)
What's a good table size to hold this many entries?
 o dbzsync()
Push all in-core data out to disk.
 o elements()
Returns an enumeration of the elements.
 o fetch(Object)
Like get(), but assumes the key has already been case-mapped.
 o get(Object)
Gets the object associated with the specified key in the dbz file.
 o isEmpty()
Returns true if the dbz file contains no elements.
 o keys()
Returns an enumeration of the dbz file's keys.
 o main(String[])
Main program - for testing etc.
 o put(Object, Object)
Puts the specified element into the Dictionary, using the specified key.
 o remove(Object)
Removes the element corresponding to the key.
 o size()
Returns the number of elements contained within the dbz file.
 o store(Object, Object)
Like put(), but assumes the key has already been case-mapped.

Constructors

 o Dbz
 public Dbz(File file) throws IOException
Constructor.

Throws: IOException
if something goes wrong

Methods

 o size
 public int size()
Returns the number of elements contained within the dbz file.

Overrides:
size in class Dictionary
 o isEmpty
 public boolean isEmpty()
Returns true if the dbz file contains no elements.

Overrides:
isEmpty in class Dictionary
 o keys
 public Enumeration keys()
Returns an enumeration of the dbz file's keys.

Overrides:
keys in class Dictionary
 o elements
 public Enumeration elements()
Returns an enumeration of the elements. Use the Enumeration methods on the returned object to fetch the elements sequentially.

Overrides:
elements in class Dictionary
 o get
 public Object get(Object key)
Gets the object associated with the specified key in the dbz file.

Parameters:
key - the key in the hash table
Returns:
s the element for the key, or null if the key is not defined in the hash table.
Overrides:
get in class Dictionary
 o put
 public Object put(Object key,
                   Object value)
Puts the specified element into the Dictionary, using the specified key. The element may be retrieved by doing a get() with the same key. The key and the element cannot be null.

Parameters:
key - the specified hashtable key
value - the specified element
Returns:
the old value of the key, or null if it did not have one.
Throws: NullPointerException
If the value of the specified element is null.
Overrides:
put in class Dictionary
 o remove
 public Object remove(Object key)
Removes the element corresponding to the key. Does nothing if the key is not present.

Parameters:
key - the key that needs to be removed
Returns:
the value of key, or null if the key was not found.
Overrides:
remove in class Dictionary
 o main
 public static void main(String args[])
Main program - for testing etc.

 o dbzsize
 public int dbzsize(int contents)
What's a good table size to hold this many entries?

 o dbmclose
 public void dbmclose()
Close a database.

 o dbzsync
 public void dbzsync()
Push all in-core data out to disk.

 o dbzcancel
 public void dbzcancel()
Cancel writing of in-core data. Mostly for use from child process.

 o fetch
 public Object fetch(Object key)
Like get(), but assumes the key has already been case-mapped.

 o store
 public Object store(Object key,
                     Object value)
Like put(), but assumes the key has already been case-mapped.

 o dbzincore
 public void dbzincore(boolean value)
Control attempts to keep .pag file in core.


All Packages  Class Hierarchy  This Package  Previous  Next  Index

ACME Java  ACME Labs