|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.coyotegulch.jisp.HashIndex
public class HashIndex
HashIndex
associates a key
value with a reference to persistent data,
using a disk-based hash table. The index assumes that the position
of a serializable
object is constant, regardless of the actual meaning of the long
position. In
general, the position represents the location (file pointer) of a Serializable
object in an IndexedObjectDatabase
.
Use the IndexedObjectDatabase.attachIndex
method to attach a BTreeIndex
to a database. A database updates all attached indexes when it writes or removes objects
from its file.
This class should not be used in new code. It was originally design to illustrate algorithms, and it suffers from a number of performance problems. A better, more efficient hash-bvased index will be introduced in version 3.0 of Jisp.
ObjectIndex
Constructor Summary | |
---|---|
HashIndex(java.lang.String name)
Deprecated. Opens a file as a HashIndex . |
|
HashIndex(java.lang.String name,
int numBuckets,
int maxRecords,
KeyObject nullKey)
Deprecated. Creates the file as a HashIndex . |
Method Summary | |
---|---|
void |
close()
Deprecated. |
long |
findKey(KeyObject key)
Deprecated. Find the position of the object associated with a given key. |
void |
insertKey(KeyObject key,
long pos)
Deprecated. Insert a key into the database, associating a record position with the given key. |
void |
optimize()
Deprecated. Improves the performance of this HashIndex by optimizing the
index contents. |
void |
removeKey(KeyObject key)
Deprecated. Removes the given key from the index. |
void |
replaceKey(KeyObject key,
long pos)
Deprecated. Replace the reference pos for the given key. |
void |
storeKey(KeyObject key,
long pos)
Deprecated. If the key already exists, replace the reference pos for the given key. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HashIndex(java.lang.String name, int numBuckets, int maxRecords, KeyObject nullKey) throws java.io.IOException, java.lang.ClassNotFoundException
HashIndex
. The initial length of each list is
based on numBuckets
and macRecords
. The null key is a "blank" key; obtain
a null key for any KeyObject
type by calling the KeyObject.makeNullKey
method.
name
- The name of the external index file to be opened.numBuckets
- The number of lists in the hash table; this is also known as the "hash factor."
Use prime numbers to limit the number of collisions and increase the
efficiency of the index.maxRecords
- The expected number of records to be indexed. This is not
a limit
on the index size; the index will expand to handle up to 2 billion records.
However, the best performance is obtained by setting maxRecords
to a value that reflects the expected size of the database.nullKey
- The null key serves two purposes: to identify a blank table entry,
and to perform type-checking on new keys added to the index. All
keys added to the index must have the same type as nullkey
.
java.io.IOException
- when an I/O exception is thrown by an underlying java.io.* class
java.lang.ClassNotFoundException
- for a casting error, usually when a persistent object or index does
match the expected typeKeyObject
public HashIndex(java.lang.String name) throws java.io.IOException, java.lang.ClassNotFoundException
HashIndex
.
name
- The name of the external index file to be opened.
java.io.IOException
- when an I/O exception is thrown by an underlying java.io.* class
java.lang.ClassNotFoundException
- for a casting error, usually when a persistent object or index does
match the expected typeMethod Detail |
---|
public void insertKey(KeyObject key, long pos) throws java.io.IOException, DuplicateKey, java.lang.ClassNotFoundException
insertKey
in interface ObjectIndex
key
- A key identifying the record to be read.pos
- File position of record associated with key
java.io.IOException
- when an I/O exception is thrown by an underlying java.io.* class
java.lang.ClassNotFoundException
- for a casting error, usually when a persistent object or index does
match the expected type
DuplicateKey
- when inserting a duplicate key into an index that does not
support duplicatesDuplicateKey
,
KeyObject
public void replaceKey(KeyObject key, long pos) throws java.io.IOException, java.lang.ClassNotFoundException
replaceKey
in interface ObjectIndex
key
- A key identifying the record to be read.pos
- File position of record associated with key
java.io.IOException
- when an I/O exception is thrown by an underlying java.io.* class
java.lang.ClassNotFoundException
- for a casting error, usually when a persistent object or index does
match the expected type
KeyNotFound
- when the specified key can not be found in the indexKeyNotFound
,
KeyObject
public void storeKey(KeyObject key, long pos) throws java.io.IOException, java.lang.ClassNotFoundException
storeKey
in interface ObjectIndex
key
- A key identifying the record to be read.pos
- File position of record associated with key
java.io.IOException
- when an I/O exception is thrown by an underlying java.io.* class
java.lang.ClassNotFoundException
- for a casting error, usually when a persistent object or index does
match the expected typeKeyObject
public long findKey(KeyObject key) throws KeyNotFound, java.io.IOException, java.lang.ClassNotFoundException
findKey
in interface ObjectIndex
key
- A key identifying the record to be read.
key
.
java.io.IOException
- when an I/O exception is thrown by an underlying java.io.* class
java.lang.ClassNotFoundException
- for a casting error, usually when a persistent object or index does
match the expected type
KeyNotFound
- when the specified key can not be found in the indexKeyNotFound
,
KeyObject
public void removeKey(KeyObject key) throws java.io.IOException, java.lang.ClassNotFoundException
removeKey
in interface ObjectIndex
key
- A key identifying the record to be read.
java.io.IOException
- when an I/O exception is thrown by an underlying java.io.* class
java.lang.ClassNotFoundException
- for a casting error, usually when a persistent object or index does
match the expected type
KeyNotFound
- when the specified key can not be found in the indexKeyNotFound
,
KeyObject
public void optimize() throws java.io.IOException, java.lang.ClassNotFoundException
HashIndex
by optimizing the
index contents.
java.io.IOException
java.lang.ClassNotFoundException
public void close() throws java.io.IOException
java.io.IOException
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |