Package com.coyotegulch.jisp
Class HashIndex
- java.lang.Object
-
- com.coyotegulch.jisp.HashIndex
-
- All Implemented Interfaces:
ObjectIndex
public class HashIndex extends java.lang.Object implements ObjectIndex
Deprecated.As of Jisp versioon 2.5.0, the HashIndex class is deprecated; it will be replaced in Jisp 3.0 by a more efficient and simpler hash-based index.HashIndexassociates akeyvalue with a reference to persistent data, using a disk-based hash table. The index assumes that thepositionof a serializable object is constant, regardless of the actual meaning of thelongposition. In general, the position represents the location (file pointer) of aSerializableobject in anIndexedObjectDatabase.Use the
IndexedObjectDatabase.attachIndexmethod to attach aBTreeIndexto 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.
- See Also:
ObjectIndex
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclose()Deprecated.longfindKey(KeyObject key)Deprecated.Find the position of the object associated with a given key.voidinsertKey(KeyObject key, long pos)Deprecated.Insert a key into the database, associating a record position with the given key.voidoptimize()Deprecated.Improves the performance of thisHashIndexby optimizing the index contents.voidremoveKey(KeyObject key)Deprecated.Removes the given key from the index.voidreplaceKey(KeyObject key, long pos)Deprecated.Replace the reference pos for the given key.voidstoreKey(KeyObject key, long pos)Deprecated.If the key already exists, replace the reference pos for the given key.
-
-
-
Constructor Detail
-
HashIndex
public HashIndex(java.lang.String name, int numBuckets, int maxRecords, KeyObject nullKey) throws java.io.IOException, java.lang.ClassNotFoundExceptionDeprecated.Creates the file as aHashIndex. The initial length of each list is based onnumBucketsandmacRecords. The null key is a "blank" key; obtain a null key for anyKeyObjecttype by calling theKeyObject.makeNullKeymethod.- Parameters:
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 isnota limit on the index size; the index will expand to handle up to 2 billion records. However, the best performance is obtained by settingmaxRecordsto 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 asnullkey.- Throws:
java.io.IOException- when an I/O exception is thrown by an underlying java.io.* classjava.lang.ClassNotFoundException- for a casting error, usually when a persistent object or index does match the expected type- See Also:
KeyObject
-
HashIndex
public HashIndex(java.lang.String name) throws java.io.IOException, java.lang.ClassNotFoundExceptionDeprecated.Opens a file as aHashIndex.- Parameters:
name- The name of the external index file to be opened.- Throws:
java.io.IOException- when an I/O exception is thrown by an underlying java.io.* classjava.lang.ClassNotFoundException- for a casting error, usually when a persistent object or index does match the expected type
-
-
Method Detail
-
insertKey
public void insertKey(KeyObject key, long pos) throws java.io.IOException, DuplicateKey, java.lang.ClassNotFoundException
Deprecated.Insert a key into the database, associating a record position with the given key.- Specified by:
insertKeyin interfaceObjectIndex- Parameters:
key- A key identifying the record to be read.pos- File position of record associated with key- Throws:
java.io.IOException- when an I/O exception is thrown by an underlying java.io.* classjava.lang.ClassNotFoundException- for a casting error, usually when a persistent object or index does match the expected typeDuplicateKey- when inserting a duplicate key into an index that does not support duplicates- See Also:
DuplicateKey,KeyObject
-
replaceKey
public void replaceKey(KeyObject key, long pos) throws java.io.IOException, java.lang.ClassNotFoundException
Deprecated.Replace the reference pos for the given key.- Specified by:
replaceKeyin interfaceObjectIndex- Parameters:
key- A key identifying the record to be read.pos- File position of record associated with key- Throws:
java.io.IOException- when an I/O exception is thrown by an underlying java.io.* classjava.lang.ClassNotFoundException- for a casting error, usually when a persistent object or index does match the expected typeKeyNotFound- when the specified key can not be found in the index- See Also:
KeyNotFound,KeyObject
-
storeKey
public void storeKey(KeyObject key, long pos) throws java.io.IOException, java.lang.ClassNotFoundException
Deprecated.If the key already exists, replace the reference pos for the given key. Otherwise, insert a key into the database, associating a record position with the given key.- Specified by:
storeKeyin interfaceObjectIndex- Parameters:
key- A key identifying the record to be read.pos- File position of record associated with key- Throws:
java.io.IOException- when an I/O exception is thrown by an underlying java.io.* classjava.lang.ClassNotFoundException- for a casting error, usually when a persistent object or index does match the expected type- See Also:
KeyObject
-
findKey
public long findKey(KeyObject key) throws KeyNotFound, java.io.IOException, java.lang.ClassNotFoundException
Deprecated.Find the position of the object associated with a given key.- Specified by:
findKeyin interfaceObjectIndex- Parameters:
key- A key identifying the record to be read.- Returns:
- The position of the record associated with
key. - Throws:
java.io.IOException- when an I/O exception is thrown by an underlying java.io.* classjava.lang.ClassNotFoundException- for a casting error, usually when a persistent object or index does match the expected typeKeyNotFound- when the specified key can not be found in the index- See Also:
KeyNotFound,KeyObject
-
removeKey
public void removeKey(KeyObject key) throws java.io.IOException, java.lang.ClassNotFoundException
Deprecated.Removes the given key from the index.- Specified by:
removeKeyin interfaceObjectIndex- Parameters:
key- A key identifying the record to be read.- Throws:
java.io.IOException- when an I/O exception is thrown by an underlying java.io.* classjava.lang.ClassNotFoundException- for a casting error, usually when a persistent object or index does match the expected typeKeyNotFound- when the specified key can not be found in the index- See Also:
KeyNotFound,KeyObject
-
optimize
public void optimize() throws java.io.IOException, java.lang.ClassNotFoundExceptionDeprecated.Improves the performance of thisHashIndexby optimizing the index contents.- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
close
public void close() throws java.io.IOExceptionDeprecated.- Throws:
java.io.IOException
-
-