org.hypergraphdb.storage
Class DefaultIndexImpl<KeyType,ValueType>

java.lang.Object
  extended by org.hypergraphdb.storage.DefaultIndexImpl<KeyType,ValueType>
All Implemented Interfaces:
HGIndex<KeyType,ValueType>, HGOrderedSearchable<KeyType,ValueType>, HGSearchable<KeyType,ValueType>, HGSortIndex<KeyType,ValueType>
Direct Known Subclasses:
DefaultBiIndexImpl

public class DefaultIndexImpl<KeyType,ValueType>
extends java.lang.Object
implements HGSortIndex<KeyType,ValueType>

A default index implementation. This implementation works by maintaining a separate DB, using a B-tree, byte [] lexicographical ordering on its keys. The keys are therefore assumed to by byte [] instances.

Author:
Borislav Iordanov

Field Summary
static java.lang.String DB_NAME_PREFIX
          Prefix of HyperGraph index DB filenames.
 
Constructor Summary
DefaultIndexImpl(java.lang.String indexName, com.sleepycat.db.Environment env, HGTransactionManager transactionManager, ByteArrayConverter<KeyType> keyConverter, ByteArrayConverter<ValueType> valueConverter, java.util.Comparator comparator)
           
 
Method Summary
 void addEntry(KeyType key, ValueType value)
           Add an entry to the index.
 void close()
           Close this index.
 long count()
          Return the number of keys in this index.
 long count(KeyType key)
          Return the number of values for the key.
 HGRandomAccessResult find(KeyType key)
           Retrieve all entries corresponding to the given key.
 ValueType findFirst(KeyType key)
           Find the first indexed entry corresponding to the given key.
 HGRandomAccessResult findGT(KeyType key)
          Return a range of all values strictly greater than the specified key.
 HGRandomAccessResult findGTE(KeyType key)
          Return a range of all values greater than or equal to the specified key.
 HGRandomAccessResult findLT(KeyType key)
          Return a range of all values strictly less than the specified key.
 HGRandomAccessResult findLTE(KeyType key)
          Return a range of all values less than or equal to the specified key.
 java.util.Comparator getComparator()
           
 java.lang.String getDatabaseName()
           
 java.lang.String getName()
           
 boolean isOpen()
          Return true if the index is currently opened and false otherwise.
 void open()
           Open the index for use.
 void removeAllEntries(KeyType key)
          Remove all entries in the index with a geven key.
 void removeEntry(KeyType key, ValueType value)
          Remove a specific entry in the index.
 HGRandomAccessResult<KeyType> scanKeys()
          Return a result set containing all keys in this index.
 HGRandomAccessResult<ValueType> scanValues()
          Return a result set containing all values in this index.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DB_NAME_PREFIX

public static final java.lang.String DB_NAME_PREFIX
Prefix of HyperGraph index DB filenames.

See Also:
Constant Field Values
Constructor Detail

DefaultIndexImpl

public DefaultIndexImpl(java.lang.String indexName,
                        com.sleepycat.db.Environment env,
                        HGTransactionManager transactionManager,
                        ByteArrayConverter<KeyType> keyConverter,
                        ByteArrayConverter<ValueType> valueConverter,
                        java.util.Comparator comparator)
Method Detail

getName

public java.lang.String getName()

getDatabaseName

public java.lang.String getDatabaseName()

getComparator

public java.util.Comparator getComparator()

open

public void open()
Description copied from interface: HGIndex

Open the index for use. Entries may be added to the index only when it has been explicitly opened. To determine whether an index is currently opened, use the isOpen method. Note that an index may be temporarily opened by the HyperGraph querying mechanism.

Specified by:
open in interface HGIndex<KeyType,ValueType>

close

public void close()
Description copied from interface: HGIndex

Close this index. This method closes any run-time resources associated with the index, and invalidates it for use until reopened. It does not remove the index permanently from the database.

Specified by:
close in interface HGIndex<KeyType,ValueType>

isOpen

public boolean isOpen()
Description copied from interface: HGIndex

Return true if the index is currently opened and false otherwise.

Specified by:
isOpen in interface HGIndex<KeyType,ValueType>

scanValues

public HGRandomAccessResult<ValueType> scanValues()
Description copied from interface: HGIndex

Return a result set containing all values in this index.

Specified by:
scanValues in interface HGIndex<KeyType,ValueType>

scanKeys

public HGRandomAccessResult<KeyType> scanKeys()
Description copied from interface: HGIndex

Return a result set containing all keys in this index.

Specified by:
scanKeys in interface HGIndex<KeyType,ValueType>

addEntry

public void addEntry(KeyType key,
                     ValueType value)
Description copied from interface: HGIndex

Add an entry to the index.

Specified by:
addEntry in interface HGIndex<KeyType,ValueType>
Parameters:
key - The entry's key part.
value - The entry's value part.

removeEntry

public void removeEntry(KeyType key,
                        ValueType value)
Description copied from interface: HGIndex

Remove a specific entry in the index. If an entry with this key and value does not exist, the method does not nothing.

Specified by:
removeEntry in interface HGIndex<KeyType,ValueType>
Parameters:
key - The key part of the entry.
value - The value part of the entry.

removeAllEntries

public void removeAllEntries(KeyType key)
Description copied from interface: HGIndex

Remove all entries in the index with a geven key. If an entry with this key does not exist, the method does not nothing.

Specified by:
removeAllEntries in interface HGIndex<KeyType,ValueType>
Parameters:
key - The key all of whose corresponding entries will be removed.

findFirst

public ValueType findFirst(KeyType key)
Description copied from interface: HGIndex

Find the first indexed entry corresponding to the given key. The first entry will generally be the one that was firstly added for that key. However, this is by no means guarantueed. This method is meant for indices where only a single value corresponds to a key. That is, in mathematical terms, indices that can be seen as functions.

Specified by:
findFirst in interface HGIndex<KeyType,ValueType>
Parameters:
key - The key whose value is sought.
Returns:
The first entry for that key.

find

public HGRandomAccessResult find(KeyType key)
Description copied from interface: HGIndex

Retrieve all entries corresponding to the given key. The order in which the entries are returned is not necessarily the order in which they were originally added.

Specified by:
find in interface HGIndex<KeyType,ValueType>
Specified by:
find in interface HGSearchable<KeyType,ValueType>
Parameters:
key - The key whose values are sought.
Returns:
A HGRandomAccessResult over all HGPersistentHandles under that key.

findGT

public HGRandomAccessResult findGT(KeyType key)
Description copied from interface: HGOrderedSearchable

Return a range of all values strictly greater than the specified key.

Specified by:
findGT in interface HGOrderedSearchable<KeyType,ValueType>
Specified by:
findGT in interface HGSortIndex<KeyType,ValueType>
Parameters:
key - The search key.
Returns:
An HGSearchResult over the resulting range of values.

findGTE

public HGRandomAccessResult findGTE(KeyType key)
Description copied from interface: HGOrderedSearchable

Return a range of all values greater than or equal to the specified key.

Specified by:
findGTE in interface HGOrderedSearchable<KeyType,ValueType>
Specified by:
findGTE in interface HGSortIndex<KeyType,ValueType>
Parameters:
key - The search key.
Returns:
An HGSearchResult over the resulting range of values.

findLT

public HGRandomAccessResult findLT(KeyType key)
Description copied from interface: HGOrderedSearchable

Return a range of all values strictly less than the specified key.

Specified by:
findLT in interface HGOrderedSearchable<KeyType,ValueType>
Specified by:
findLT in interface HGSortIndex<KeyType,ValueType>
Parameters:
key - The search key.
Returns:
An HGSearchResult over the resulting range of values.

findLTE

public HGRandomAccessResult findLTE(KeyType key)
Description copied from interface: HGOrderedSearchable

Return a range of all values less than or equal to the specified key.

Specified by:
findLTE in interface HGOrderedSearchable<KeyType,ValueType>
Specified by:
findLTE in interface HGSortIndex<KeyType,ValueType>
Parameters:
key - The search key.
Returns:
An HGSearchResult over the resulting range of values.

count

public long count()
Description copied from interface: HGIndex

Return the number of keys in this index. This operation must run in constant time, regardless of the number of keys.

Specified by:
count in interface HGIndex<KeyType,ValueType>

count

public long count(KeyType key)
Description copied from interface: HGIndex

Return the number of values for the key. This operation must run constant time regardless of the key or the number returned.

Specified by:
count in interface HGIndex<KeyType,ValueType>
Parameters:
key - The key whose values must be counted.