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.
Modifier and Type | Field and Description |
---|---|
protected java.util.Comparator<?> |
comparator |
protected CursorConfig |
cursorConfig |
protected Database |
db |
static java.lang.String |
DB_NAME_PREFIX
Prefix of HyperGraph index DB filenames.
|
protected ByteArrayConverter<KeyType> |
keyConverter |
protected java.lang.String |
name |
protected boolean |
sort_duplicates |
protected BJEStorageImplementation |
storage |
protected HGTransactionManager |
transactionManager |
protected ByteArrayConverter<ValueType> |
valueConverter |
Constructor and Description |
---|
DefaultIndexImpl(java.lang.String indexName,
BJEStorageImplementation storage,
HGTransactionManager transactionManager,
ByteArrayConverter<KeyType> keyConverter,
ByteArrayConverter<ValueType> valueConverter,
java.util.Comparator<?> comparator) |
Modifier and Type | Method and Description |
---|---|
void |
addEntry(KeyType key,
ValueType value)
Add an entry to the index.
|
protected void |
checkOpen() |
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.
|
protected void |
finalize() |
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.
|
HGSearchResult<ValueType> |
findGT(KeyType key)
Return a range of all values strictly greater than
the specified key.
|
HGSearchResult<ValueType> |
findGTE(KeyType key)
Return a range of all values greater than or equal to
the specified key.
|
ValueType |
findLast(KeyType key)
Find the last entry, assuming ordered duplicates, corresponding to the
given key.
|
HGSearchResult<ValueType> |
findLT(KeyType key)
Return a range of all values strictly less than
the specified key.
|
HGSearchResult<ValueType> |
findLTE(KeyType key)
Return a range of all values less than or equal to
the specified key.
|
java.util.Comparator<byte[]> |
getComparator() |
ValueType |
getData(KeyType key) |
java.lang.String |
getDatabaseName() |
java.lang.String |
getName()
Return the unique name that identifies this index at the storage layer.
|
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 given 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.
|
protected TransactionBJEImpl |
txn() |
public static final java.lang.String DB_NAME_PREFIX
protected BJEStorageImplementation storage
protected CursorConfig cursorConfig
protected HGTransactionManager transactionManager
protected java.lang.String name
protected Database db
protected java.util.Comparator<?> comparator
protected boolean sort_duplicates
protected ByteArrayConverter<KeyType> keyConverter
protected ByteArrayConverter<ValueType> valueConverter
public DefaultIndexImpl(java.lang.String indexName, BJEStorageImplementation storage, HGTransactionManager transactionManager, ByteArrayConverter<KeyType> keyConverter, ByteArrayConverter<ValueType> valueConverter, java.util.Comparator<?> comparator)
protected void checkOpen()
protected TransactionBJEImpl txn()
public java.lang.String getName()
HGIndex
public java.lang.String getDatabaseName()
public java.util.Comparator<byte[]> getComparator()
public void open()
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.
public void close()
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.
public boolean isOpen()
HGIndex
Return true
if the index is currently opened and
false
otherwise.
public HGRandomAccessResult<ValueType> scanValues()
HGIndex
Return a result set containing all values in this index.
scanValues
in interface HGIndex<KeyType,ValueType>
public HGRandomAccessResult<KeyType> scanKeys()
HGIndex
Return a result set containing all keys in this index.
public void addEntry(KeyType key, ValueType value)
HGIndex
Add an entry to the index. If that entry is already present, calling this method should have no effect.
public void removeEntry(KeyType key, ValueType value)
HGIndex
Remove a specific entry in the index. If an entry with this key and value does not exist, the method does not nothing.
removeEntry
in interface HGIndex<KeyType,ValueType>
key
- The key part of the entry.value
- The value part of the entry.public void removeAllEntries(KeyType key)
HGIndex
Remove all entries in the index with a given key. If an entry with this key does not exist, the method does not nothing.
removeAllEntries
in interface HGIndex<KeyType,ValueType>
key
- The key all of whose corresponding entries will be removed.public ValueType findFirst(KeyType key)
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 guaranteed. 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.
public ValueType findLast(KeyType key)
Find the last entry, assuming ordered duplicates, corresponding to the given key.
key
- The key whose last entry is sought.public HGRandomAccessResult<ValueType> find(KeyType key)
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.
public HGSearchResult<ValueType> findGT(KeyType key)
HGOrderedSearchable
Return a range of all values strictly greater than the specified key.
findGT
in interface HGOrderedSearchable<KeyType,ValueType>
findGT
in interface HGSortIndex<KeyType,ValueType>
key
- The search key.HGSearchResult
over the resulting range of values.public HGSearchResult<ValueType> findGTE(KeyType key)
HGOrderedSearchable
Return a range of all values greater than or equal to the specified key.
findGTE
in interface HGOrderedSearchable<KeyType,ValueType>
findGTE
in interface HGSortIndex<KeyType,ValueType>
key
- The search key.HGSearchResult
over the resulting range of values.public HGSearchResult<ValueType> findLT(KeyType key)
HGOrderedSearchable
Return a range of all values strictly less than the specified key.
findLT
in interface HGOrderedSearchable<KeyType,ValueType>
findLT
in interface HGSortIndex<KeyType,ValueType>
key
- The search key.HGSearchResult
over the resulting range of values.public HGSearchResult<ValueType> findLTE(KeyType key)
HGOrderedSearchable
Return a range of all values less than or equal to the specified key.
findLTE
in interface HGOrderedSearchable<KeyType,ValueType>
findLTE
in interface HGSortIndex<KeyType,ValueType>
key
- The search key.HGSearchResult
over the resulting range of values.protected void finalize()
finalize
in class java.lang.Object
public long count()
HGIndex
Return the number of keys in this index. This operation must run in constant time, regardless of the number of keys.