|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.equitysoft.hashstore.DiskHashtable
This class implements a hashtable on disk. It mimics the behaviour of java.util.Hashtable
with
identical methods to put, get and remove instances from the table.
The underlying file system is used to allocate and deallocate space for storage so no initial capacity or load factor need be specified. A capacity of one billion keys is hardcoded into the class. Disk space is only requested from the file system piece by piece and when required so the programmer need not be concerned if a few hundred or a few million entries are being stored. Performance should always be the same no matter how many keys are stored.
None of the methods are synchronized. The class SyncDiskHashtable
provides a synchronized version.
Constructor Summary | |
DiskHashtable(java.io.File root)
|
Method Summary | |
void |
clear()
Removes all the keys and values in the table. |
boolean |
containsKey(java.lang.Object key)
Returns true true if the hashtable contains the given key otherwise false . |
void |
deleteTable()
Deletes all the files and directories associated with the table and leaves nothing behind. |
java.util.Enumeration |
elements()
Returns an Enumeration of all the values in the hashtable. |
java.lang.Object |
get(java.lang.Object key)
Gets the object associated with the key. |
boolean |
isEmpty()
Returns true if the table contains at least one entry. |
java.util.Enumeration |
keys()
Returns an Enumeration of all the keys in the hashtable. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Puts the specified key and value pair into the table and returns the original
value for the key if the key already exists. |
java.lang.Object |
remove(java.lang.Object key)
Removes the specified key from the hashtable |
int |
size()
Returns the number of entries in the hashtable. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public DiskHashtable(java.io.File root)
Method Detail |
public java.lang.Object put(java.lang.Object key, java.lang.Object value) throws java.io.IOException
key
and value
pair into the table and returns the original
value for the key if the key already exists.public java.lang.Object get(java.lang.Object key) throws java.io.IOException
ClassNotFoundException
when deserializing then the exception is transformed into an IOException
for convenience.null
if the key isn't found otherwise the associated objectpublic java.lang.Object remove(java.lang.Object key) throws java.io.IOException
public boolean containsKey(java.lang.Object key) throws java.io.IOException
true
if the hashtable contains the given key otherwise false
. This
method is implemented by seeing if invoking get
returns null
.true
if the key existspublic boolean isEmpty()
true
is there are no entries in the hashtable.public int size()
public java.util.Enumeration keys()
Enumeration
of all the keys in the hashtable. Repeated getNextElement
calls
will then return the hashtable keys. It is more efficient to make repeated called of getNextElement
until a null
value is returned instead of using hasMoreElements
.elements()
public java.util.Enumeration elements()
Enumeration
of all the values in the hashtable. Repeated getNextElement
calls
will then return the hashtable values. It is more efficient to make repeated called of getNextElement
until a null
value is returned instead of using hasMoreElements
. The enumeration order
will be the same as keys()
.keys()
public void clear()
deleteTable()
public void deleteTable()
clear()
before invoking this method.
The method won't return until the operation is complete and may take some time. It is always synchronized as only
one thread should do this.clear()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |