net.obsearch.index.bucket
Class AbstractBucketIndex<O extends OB,B extends BucketObject,Q,BC extends BucketContainer<O,B,Q>>

java.lang.Object
  extended by net.obsearch.index.AbstractOBIndex<O>
      extended by net.obsearch.index.pivot.AbstractPivotOBIndex<O>
          extended by net.obsearch.index.bucket.AbstractBucketIndex<O,B,Q,BC>
All Implemented Interfaces:
Index<O>
Direct Known Subclasses:
AbstractBucketSorter, AbstractDistancePermutations

public abstract class AbstractBucketIndex<O extends OB,B extends BucketObject,Q,BC extends BucketContainer<O,B,Q>>
extends AbstractPivotOBIndex<O>


Nested Class Summary
protected  class AbstractBucketIndex.BucketIterator
           
 
Field Summary
protected  OBStore<TupleBytes> Buckets
          We store the buckets in this storage device.
 
Fields inherited from class net.obsearch.index.pivot.AbstractPivotOBIndex
intrinsicDimensionalityPairs, pivots, pivotSelector
 
Fields inherited from class net.obsearch.index.AbstractOBIndex
A, fact, isFrozen, stats, type
 
Fields inherited from interface net.obsearch.Index
ID_SIZE
 
Constructor Summary
AbstractBucketIndex()
           
AbstractBucketIndex(Class<O> type, IncrementalPivotSelector<O> pivotSelector, int pivotCount)
           
 
Method Summary
protected  void bucketStats()
           
 void close()
          Closes the database.
 String debug(O object)
          Print debug info.
 OperationStatus deleteAux(O object)
          Deletes the entry of this object in the index.
 OperationStatus exists(O object)
          Returns true if the given object exists in the database.
protected  void freezeDefault()
           
abstract  byte[] getAddress(B bucket)
          Gets the byte address of the given object
abstract  B getBucket(O object)
          Returns the bucket information for the given object.
protected  BC getBucketContainer(byte[] id)
           
 OBStore<TupleBytes> getBuckets()
           
protected  O getObjectFreeze(long id, cern.colt.list.LongArrayList elementSource)
          Auxiliary function used in freeze to get objects directly from the DB, or by using an array of object ids.
protected  long idMap(long id, cern.colt.list.LongArrayList elementSource)
          If elementSource == null returns id, otherwise it returns elementSource[id]
 void init(OBStoreFactory fact)
          Initialize the index.
protected  void initByteArrayBuckets()
          Initializes the bucket byte array storage.
 OperationStatus insertAux(long id, O object)
          Inserts the given object into the particular index.
 OperationStatus insertAuxBulk(long id, O object)
          Inserts the given object into the particular index.
protected  OperationStatus insertBucket(B b, O object)
          Stores the given bucket b into the Buckets storage device.
protected  OperationStatus insertBucketBulk(B b, O object)
          Stores the given bucket b into the Buckets storage device.
protected abstract  BC instantiateBucketContainer(byte[] data, byte[] address)
          Get a bucket container from the given data.
 Iterator<BC> iterateBuckets()
          Useful iterator for buckets.
protected abstract  int primitiveDataTypeSize()
          Return the size in bytes of the underlying primitive datatype.
 
Methods inherited from class net.obsearch.index.pivot.AbstractPivotOBIndex
calculateIntrinsicDimensionality, createPivotsArray, freeze, getObjects, getPivotCount, selectPivots
 
Methods inherited from class net.obsearch.index.AbstractOBIndex
assertFrozen, bytesToObject, bytesToObject, clearACache, databaseSize, delete, distance, emptyPivotsArray, findAux, getBox, getObject, getStats, getType, initCache, initStorageDevices, insert, insert, insertBulk, insertBulk, intrinsicDimensionality, isFrozen, isPreFreeze, isPreFreezeCheck, loadObject, loadPivots, objectToByteBuffer, objectToBytes, resetStats, serializePivots, setFixedRecord, setFixedRecord, setIdAutoGeneration, setPreFreeze, setPreFreezeCheck, totalBoxes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Buckets

protected transient OBStore<TupleBytes> Buckets
We store the buckets in this storage device.

Constructor Detail

AbstractBucketIndex

public AbstractBucketIndex(Class<O> type,
                           IncrementalPivotSelector<O> pivotSelector,
                           int pivotCount)
                    throws OBStorageException,
                           OBException
Throws:
OBStorageException
OBException

AbstractBucketIndex

public AbstractBucketIndex()
Method Detail

idMap

protected long idMap(long id,
                     cern.colt.list.LongArrayList elementSource)
              throws OBException
If elementSource == null returns id, otherwise it returns elementSource[id]

Returns:
Throws:
OBException

getObjectFreeze

protected O getObjectFreeze(long id,
                            cern.colt.list.LongArrayList elementSource)
                                throws IllegalIdException,
                                       IllegalAccessException,
                                       InstantiationException,
                                       OutOfRangeException,
                                       OBException
Auxiliary function used in freeze to get objects directly from the DB, or by using an array of object ids.

Throws:
IllegalIdException
IllegalAccessException
InstantiationException
OutOfRangeException
OBException

iterateBuckets

public Iterator<BC> iterateBuckets()
                                                           throws OBStorageException,
                                                                  OBException
Useful iterator for buckets.

Returns:
Throws:
OBException
OBStorageException

getBucket

public abstract B getBucket(O object)
                                          throws OBException,
                                                 InstantiationException,
                                                 IllegalAccessException
Returns the bucket information for the given object.

Parameters:
object - The object that will be calculated
Returns:
The bucket information for the given object.
Throws:
IllegalAccessException
OBException
InstantiationException

initByteArrayBuckets

protected void initByteArrayBuckets()
                             throws OBException
Initializes the bucket byte array storage. To be called by the init procedure.

Throws:
OBException

primitiveDataTypeSize

protected abstract int primitiveDataTypeSize()
Return the size in bytes of the underlying primitive datatype.

Returns:

init

public void init(OBStoreFactory fact)
          throws OBStorageException,
                 OBException,
                 InstantiationException,
                 IllegalAccessException
Description copied from class: AbstractOBIndex
Initialize the index.

Specified by:
init in interface Index<O extends OB>
Overrides:
init in class AbstractPivotOBIndex<O extends OB>
Parameters:
fact - The storage factory that will be used to store the data.
Throws:
OBStorageException - If something goes wrong with the DB
OBException - User generated exception
NotFrozenException - if the index has not been frozen.
InstantiationException - If there is a problem when instantiating objects O
IllegalAccessException - If there is a problem when instantiating objects O

insertBucket

protected OperationStatus insertBucket(B b,
                                       O object)
                                throws OBStorageException,
                                       IllegalIdException,
                                       IllegalAccessException,
                                       InstantiationException,
                                       OutOfRangeException,
                                       OBException
Stores the given bucket b into the Buckets storage device. The given bucket b should have been returned by #getBucket(OB, int)

Parameters:
b - The bucket in which we will insert the object.
object - The object to insert.
Returns:
A OperationStatus object with the new id of the object if the object was inserted successfully.
Throws:
OBStorageException
IllegalIdException
IllegalAccessException
InstantiationException
OutOfRangeException
OBException

getBucketContainer

protected BC getBucketContainer(byte[] id)
                                                        throws OBException,
                                                               InstantiationException,
                                                               IllegalAccessException
Throws:
OBException
InstantiationException
IllegalAccessException

insertBucketBulk

protected OperationStatus insertBucketBulk(B b,
                                           O object)
                                    throws OBStorageException,
                                           IllegalIdException,
                                           IllegalAccessException,
                                           InstantiationException,
                                           OutOfRangeException,
                                           OBException
Stores the given bucket b into the Buckets storage device. The given bucket b should have been returned by #getBucket(OB, int) No checks are performed, we simply add the objects believing they are unique.

Parameters:
b - The bucket in which we will insert the object.
object - The object to insert.
Returns:
A OperationStatus object with the new id of the object if the object was inserted successfully.
Throws:
OBStorageException
IllegalIdException
IllegalAccessException
InstantiationException
OutOfRangeException
OBException

exists

public OperationStatus exists(O object)
                       throws OBException,
                              IllegalAccessException,
                              InstantiationException
Description copied from interface: Index
Returns true if the given object exists in the database. This method was created for OBSearch internal use. If you are relying on this method a lot, isn't it better to use a hash table or a B-tree instead of OBSearch? O.equals(...) is used to calculate the equality of two objects.

Parameters:
object - The object that will be searched.
Returns:
Status.EXISTS and the object's id if the object exists in the database, otherwise Status.NOT_EXISTS is returned.
Throws:
OBStorageException - If something goes wrong with the DB
OBException - User generated exception
IllegalAccessException - If there is a problem when instantiating objects O
InstantiationException - If there is a problem when instantiating objects O

freezeDefault

protected void freezeDefault()
                      throws AlreadyFrozenException,
                             IllegalIdException,
                             IllegalAccessException,
                             InstantiationException,
                             OutOfRangeException,
                             OBException
Throws:
AlreadyFrozenException
IllegalIdException
IllegalAccessException
InstantiationException
OutOfRangeException
OBException

close

public void close()
           throws OBException
Description copied from interface: Index
Closes the database.

Specified by:
close in interface Index<O extends OB>
Overrides:
close in class AbstractOBIndex<O extends OB>
Throws:
OBStorageException - If something goes wrong with the DB.
OBException

getAddress

public abstract byte[] getAddress(B bucket)
                           throws OBException
Gets the byte address of the given object

Parameters:
object - An object.
Returns:
The rosa filter value of the given object.
Throws:
OBException

bucketStats

protected void bucketStats()
                    throws OBStorageException,
                           IllegalIdException,
                           IllegalAccessException,
                           InstantiationException,
                           OBException
Throws:
OBStorageException
IllegalIdException
IllegalAccessException
InstantiationException
OBException

deleteAux

public OperationStatus deleteAux(O object)
                          throws OBException,
                                 IllegalAccessException,
                                 InstantiationException
Description copied from class: AbstractOBIndex
Deletes the entry of this object in the index. The current class will remove the object from A if the result status is Status.OK.

Specified by:
deleteAux in class AbstractOBIndex<O extends OB>
Parameters:
object - object to be deleted.
Returns:
Status.OK if the object was deleted. Status.NOT_EXISTS no object matched.
Throws:
OBException
IllegalAccessException
InstantiationException

getBuckets

public OBStore<TupleBytes> getBuckets()

insertAux

public OperationStatus insertAux(long id,
                                 O object)
                          throws OBException,
                                 IllegalAccessException,
                                 InstantiationException
Description copied from class: AbstractOBIndex
Inserts the given object into the particular index. The caller inserts the actual object so the implementing class only has to worry about adding the id inside the index.

Specified by:
insertAux in class AbstractOBIndex<O extends OB>
Parameters:
id - The id that will be used to insert the object.
object - The object that will be inserted.
Returns:
If Status.OK or Status.EXISTS then the result will hold the id of the inserted object and the operation is successful. Otherwise an exception will be thrown.
Throws:
OBStorageException
OBException
IllegalAccessException
InstantiationException

insertAuxBulk

public OperationStatus insertAuxBulk(long id,
                                     O object)
                              throws OBException,
                                     IllegalAccessException,
                                     InstantiationException
Description copied from class: AbstractOBIndex
Inserts the given object into the particular index. No checks regarding existence are performed. We assume the user already checked uniqueness.

Specified by:
insertAuxBulk in class AbstractOBIndex<O extends OB>
Parameters:
id - The id that will be used to insert the object.
object - The object that will be inserted.
Returns:
Status.OK
Throws:
OBStorageException
OBException
IllegalAccessException
InstantiationException

instantiateBucketContainer

protected abstract BC instantiateBucketContainer(byte[] data,
                                                 byte[] address)
                                                                         throws InstantiationException,
                                                                                IllegalAccessException,
                                                                                OBException
Get a bucket container from the given data.

Parameters:
data - The data from which the bucket container will be loaded.
Returns:
A new bucket container ready to be used.
Throws:
IOException
OBException
IllegalAccessException
InstantiationException

debug

public String debug(O object)
             throws OBException,
                    InstantiationException,
                    IllegalAccessException
Print debug info. of the given object.

Specified by:
debug in interface Index<O extends OB>
Overrides:
debug in class AbstractOBIndex<O extends OB>
Throws:
OBException
InstantiationException
IllegalAccessException


Copyright © 2007-2011 Arnoldo Jose Muller Molina. All Rights Reserved.