org.hypergraphdb
Interface HGIndex<KeyType,ValueType>

All Superinterfaces:
HGSearchable<KeyType,ValueType>
All Known Subinterfaces:
HGBidirectionalIndex<KeyType,ValueType>, HGSortIndex<KeyType,ValueType>
All Known Implementing Classes:
DefaultBiIndexImpl, DefaultIndexImpl

public interface HGIndex<KeyType,ValueType>
extends HGSearchable<KeyType,ValueType>

The HGIndex interface represents an user-created index in the HyperGraph data structure.

Taking advantage of the new Java 1.5 feature allowing overriding methods to further specialize on the return type (i.e. allowing contravariant return types), the find method of the super-interface is redeclared to return a HGRandomAccessResult.

Author:
Borislav Iordanov

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<ValueType> 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.
 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.
 

Method Detail

addEntry

void addEntry(KeyType key,
              ValueType value)

Add an entry to the index. If that entry is already present, calling this method should have no effect.

Parameters:
key - The entry's key part.
value - The entry's value part.

removeEntry

void removeEntry(KeyType key,
                 ValueType value)

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

Parameters:
key - The key part of the entry.
value - The value part of the entry.

removeAllEntries

void removeAllEntries(KeyType key)

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

Parameters:
key - The key all of whose corresponding entries will be removed.

findFirst

ValueType findFirst(KeyType key)

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.

Parameters:
key - The key whose value is sought.
Returns:
The first entry for that key.

find

HGRandomAccessResult<ValueType> find(KeyType key)

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 HGSearchable<KeyType,ValueType>
Parameters:
key - The key whose values are sought.
Returns:
A HGRandomAccessResult over all HGPersistentHandles under that key.

open

void open()

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.


close

void close()

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.


isOpen

boolean isOpen()

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


scanKeys

HGRandomAccessResult<KeyType> scanKeys()

Return a result set containing all keys in this index.


scanValues

HGRandomAccessResult<ValueType> scanValues()

Return a result set containing all values in this index.


count

long count()

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


count

long count(KeyType key)

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

Parameters:
key - The key whose values must be counted.