|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmessif.utility.SortedArrayData<K,LongStorageMemoryIndex.KeyAddressPair<K>>
messif.buckets.index.impl.LongStorageMemoryIndex<K,T>
K
- the type of keys this index is ordered byT
- the type of objects stored in this collectionpublic class LongStorageMemoryIndex<K,T>
Implementation of disk (long) index that stores the indexed data in a sorted array and keeps the keys to be compared always in memory.
All search methods are correctly implemented using binary search on the array whenever possible.
Nested Class Summary | |
---|---|
protected static class |
LongStorageMemoryIndex.KeyAddressPair<K>
Class encapsulating the key and long position in the storage. |
Constructor Summary | |
---|---|
LongStorageMemoryIndex(DiskStorage<T> storage,
IndexComparator<K,T> comparator)
Creates a new instance of LongStorageMemoryIndex for the specified storage. |
Method Summary | ||
---|---|---|
boolean |
add(T object)
Adds the specified object to this instance. |
|
IndexComparator<K,T> |
comparator()
Returns the comparator that defines order of this index. |
|
protected int |
compare(K key,
LongStorageMemoryIndex.KeyAddressPair<K> object)
Compares its two arguments for order. |
|
void |
destroy()
Destroy this index. |
|
void |
finalize()
Finalize this index. |
|
protected LongStorageMemoryIndex.KeyAddressPair<K> |
get(int i)
Returns the element at the specified position in this collection. |
|
protected int |
insertionPoint(K key)
Searches for the point where to insert the object object . |
|
protected Lock |
lock()
Locks this index and returns a lock object if it is supported. |
|
protected boolean |
remove(int i)
Removes the element at the specified position in this collection - from both index and storage. |
|
void |
reorderStorage(java.io.File newFile)
Switches this index to a new storage in which the data are ordered according the this index's current order. |
|
StorageSearch<T> |
search()
Returns a search for all objects in this index. |
|
StorageSearch<T> |
search(java.util.Collection<? extends K> keys)
Returns a search for objects in this index using the internal OrderedIndex.comparator() of this index. |
|
|
search(IndexComparator<? super C,? super T> comparator,
C key)
Returns a search for objects in this index that have any of the specified keys. |
|
|
search(IndexComparator<? super C,? super T> comparator,
C from,
C to)
Returns a search for objects in this index that are within the specified key-range. |
|
|
search(IndexComparator<? super C,? super T> comparator,
java.util.Collection<? extends C> keys)
Returns a search for objects in this index that have any of the specified keys. |
|
StorageSearch<T> |
search(K key,
boolean restrictEqual)
Returns a search for objects in this index using the internal OrderedIndex.comparator() of this index. |
|
StorageSearch<T> |
search(K from,
K to)
Returns a search for objects in this index using the internal OrderedIndex.comparator() of this index. |
|
StorageSearch<T> |
search(K startKey,
K from,
K to)
Returns a search for objects in this index using the internal OrderedIndex.comparator() of this index. |
|
int |
size()
Returns the number of elements in this collection. |
Methods inherited from class messif.utility.SortedArrayData |
---|
binarySearch, first, fullSearch, indexOf, last, mergeSort |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public LongStorageMemoryIndex(DiskStorage<T> storage, IndexComparator<K,T> comparator)
storage
- the storage to associate with this indexcomparator
- the comparator imposing natural order of this indexMethod Detail |
---|
public void finalize() throws java.lang.Throwable
ModifiableIndex
finalize
in interface ModifiableIndex<T>
finalize
in class java.lang.Object
java.lang.Throwable
- if there was an error while cleaningpublic void destroy() throws java.lang.Throwable
ModifiableIndex
destroy
in interface ModifiableIndex<T>
java.lang.Throwable
- if there was an error while cleaningpublic IndexComparator<K,T> comparator()
OrderedIndex
comparator
in interface OrderedIndex<K,T>
protected int compare(K key, LongStorageMemoryIndex.KeyAddressPair<K> object) throws java.lang.ClassCastException
SortedArrayData
compare
in class SortedArrayData<K,LongStorageMemoryIndex.KeyAddressPair<K>>
key
- the key to indexCompareobject
- the object to be compared
java.lang.ClassCastException
- if the arguments' types prevent them from
being compared by this comparator.public void reorderStorage(java.io.File newFile) throws java.io.IOException, BucketStorageException
newFile
- the file where the new storage is created
java.io.IOException
- if there was a problem writing the the new storage
BucketStorageException
- if there was a problem reading objects from the old storage or writing them to the new onepublic int size()
SortedArrayData
size
in interface Index<T>
size
in class SortedArrayData<K,LongStorageMemoryIndex.KeyAddressPair<K>>
protected int insertionPoint(K key) throws BucketStorageException
object
.
key
- key of the object to be inserted
BucketStorageException
- if there was a problem determining the pointpublic boolean add(T object) throws BucketStorageException
Addible
add
in interface Addible<T>
object
- the object to be added
BucketStorageException
- if there was an error adding the objectprotected boolean remove(int i)
i
- index of the element to remove
protected LongStorageMemoryIndex.KeyAddressPair<K> get(int i) throws java.lang.IndexOutOfBoundsException, java.lang.IllegalStateException
SortedArrayData
get
in class SortedArrayData<K,LongStorageMemoryIndex.KeyAddressPair<K>>
i
- index of the element to return
java.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size())
java.lang.IllegalStateException
- if the object at position index
cannot be accessedprotected Lock lock()
Lock.unlock()
method if this method has returned non-null.
public StorageSearch<T> search() throws java.lang.IllegalStateException
Index
search
in interface Index<T>
search
in interface ModifiableIndex<T>
java.lang.IllegalStateException
- if there was an error initializing the search on this indexpublic StorageSearch<T> search(K key, boolean restrictEqual) throws java.lang.IllegalStateException
OrderedIndex
OrderedIndex.comparator()
of this index.
If the restrictEqual
is true, the search returns only
objects that are comparator-equal to key
.
Objects are returned in the order defined by this index.
search
in interface ModifiableOrderedIndex<K,T>
search
in interface OrderedIndex<K,T>
key
- the key to search forrestrictEqual
- if true, the search is restricted
only to objects that are comparator-equal to key
java.lang.IllegalStateException
- if there was an error initializing the search on this indexpublic StorageSearch<T> search(K from, K to) throws java.lang.IllegalStateException
OrderedIndex
OrderedIndex.comparator()
of this index.
All objects from the interval [from, to]
are returned. If a null
value is specified as a boundary, that bound is not restricted. That means that
search(x, null)
will return all objects from this index that are bigger than
or equal to x
.
Objects are returned in the order defined by this index.
search
in interface ModifiableOrderedIndex<K,T>
search
in interface OrderedIndex<K,T>
from
- the lower bound on the searched objects, i.e. objects greater or equal are returnedto
- the upper bound on the searched objects, i.e. objects smaller or equal are returned
java.lang.IllegalStateException
- if there was an error initializing the search on this indexpublic StorageSearch<T> search(K startKey, K from, K to) throws java.lang.IllegalStateException
OrderedIndex
OrderedIndex.comparator()
of this index.
All objects from the interval [from, to]
are returned. Search
starts at the object nearest to the given startKey
. If a null
value is specified as a boundary, that bound is not restricted. That means that
search(start, x, null)
will return all objects from this index that are bigger than
or equal to x
starting at object with key start
.
Objects are returned in the order defined by this index.
search
in interface ModifiableOrderedIndex<K,T>
search
in interface OrderedIndex<K,T>
startKey
- the key from which to start the searchfrom
- the lower bound on the searched objects, i.e. objects greater or equal are returnedto
- the upper bound on the searched objects, i.e. objects smaller or equal are returned
java.lang.IllegalStateException
- if there was an error initializing the search on this indexpublic StorageSearch<T> search(java.util.Collection<? extends K> keys) throws java.lang.IllegalStateException
OrderedIndex
OrderedIndex.comparator()
of this index.
All objects that are comparator
-equal to any of the given keys
are returned.
Objects are returned in the order defined by this index.
search
in interface ModifiableOrderedIndex<K,T>
search
in interface OrderedIndex<K,T>
keys
- the keys to search for
java.lang.IllegalStateException
- if there was an error initializing the search on this indexpublic <C> StorageSearch<T> search(IndexComparator<? super C,? super T> comparator, C key) throws java.lang.IllegalStateException
Index
key
need not necessarily be of the same class as the objects stored
in this index and also consistency with equals
is not required.
Note that objects are not necessarily returned in the order defined by the comparator
search
in interface Index<T>
search
in interface ModifiableIndex<T>
C
- the type of the key used by the searchcomparator
- compares the key
with the stored objectskey
- the key to search for
java.lang.IllegalStateException
- if there was an error initializing the search on this indexpublic <C> StorageSearch<T> search(IndexComparator<? super C,? super T> comparator, C from, C to) throws java.lang.IllegalStateException
Index
[from, to]
need not necessarily be of the same
class as the objects stored in this index, however, the comparator must be
able to compare the boundaries and the internal objects.
Note that objects are not returned in the order defined by the comparator
search
in interface Index<T>
search
in interface ModifiableIndex<T>
C
- the type the boundaries used by the searchcomparator
- compares the boundaries [from, to]
with the stored objectsfrom
- the lower bound on the searched objects, i.e. objects greater or equal are returnedto
- the upper bound on the searched objects, i.e. objects smaller or equal are returned
java.lang.IllegalStateException
- if there was an error initializing the search on this indexpublic <C> StorageSearch<T> search(IndexComparator<? super C,? super T> comparator, java.util.Collection<? extends C> keys) throws java.lang.IllegalStateException
Index
key
need not necessarily be of the same class as the objects stored
in this index and also consistency with equals
is not required.
Note that objects are not necessarily returned in the order defined by the comparator
search
in interface Index<T>
search
in interface ModifiableIndex<T>
C
- the type of the keys used by the searchcomparator
- compares the keys
with the stored objectskeys
- the keys to search for (at least one key must be given)
java.lang.IllegalStateException
- if there was an error initializing the search on this index
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |