messif.objects
Class PrecomputedDistancesFixedArrayFilter

java.lang.Object
  extended by messif.objects.PrecomputedDistancesFilter
      extended by messif.objects.PrecomputedDistancesFixedArrayFilter
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, BinarySerializable
Direct Known Subclasses:
PrecompDistPerforatedArrayFilter

public class PrecomputedDistancesFixedArrayFilter
extends PrecomputedDistancesFilter

Precomputed distance filter that has a fixed array of distances. While filtering, this filter uses one stored distance after the other and matches it agains the opposite object's distance.

See Also:
Serialized Form

Field Summary
protected  int actualSize
          The actual size of precompDist (if it was pre-buffered)
protected  float[] precompDist
          The list of precomputed distances
 
Fields inherited from class messif.objects.PrecomputedDistancesFilter
counterPrecomputedDistanceSavings
 
Constructor Summary
  PrecomputedDistancesFixedArrayFilter()
          Creates a new instance of PrecomputedDistancesFixedArrayFilter.
protected PrecomputedDistancesFixedArrayFilter(BinaryInput input, BinarySerializator serializator)
          Creates a new instance of PrecomputedDistancesFixedArrayFilter loaded from binary input.
  PrecomputedDistancesFixedArrayFilter(int initialSize)
          Creates a new instance of PrecomputedDistancesFixedArrayFilter.
  PrecomputedDistancesFixedArrayFilter(LocalAbstractObject object)
          Creates a new instance of PrecomputedDistancesFixedArrayFilter.
  PrecomputedDistancesFixedArrayFilter(LocalAbstractObject object, int initialSize)
          Creates a new instance of PrecomputedDistancesFixedArrayFilter
  PrecomputedDistancesFixedArrayFilter(java.lang.String distancesString)
          Creates a new instance of PrecomputedDistancesFixedArrayFilter from a string.
 
Method Summary
 int addPrecompDist(AbstractObjectList<LocalAbstractObject> pivots, LocalAbstractObject obj)
          Add distances at the end of internal list of precomputed distances.
 int addPrecompDist(float dist)
          Add distance at the end of internal list of precomputed distances.
 int addPrecompDist(float[] dists)
          Add the passed distances at the end of internal list of precomputed distances.
 int addPrecompDist(LocalAbstractObject[] pivots, LocalAbstractObject obj)
          Add distances at the end of internal list of precomputed distances.
 float addPrecompDist(LocalAbstractObject p, LocalAbstractObject o)
          Add distance at the end of internal list of precomputed distances.
 int binarySerialize(BinaryOutput output, BinarySerializator serializator)
          Binary-serialize this object into the output.
 java.lang.Object clone()
          Creates and returns a copy of this object.
protected  boolean excludeUsingPrecompDistImpl(PrecomputedDistancesFilter targetFilter, float radius)
          Returns true if object associated with targetFilter filter can be excluded (filtered out) using this precomputed distances.
protected  boolean excludeUsingPrecompDistImpl(PrecomputedDistancesFixedArrayFilter targetFilter, float radius)
          Return true if the obj has been filtered out using stored precomputed distance.
 int getBinarySize(BinarySerializator serializator)
          Returns the exact size of the binary-serialized version of this object in bytes.
 float[] getPrecompDist()
          Return the whole array of precomputed distances.
 float getPrecompDist(int position)
          Returns the precomputed distance at the specified index.
 int getPrecompDistSize()
          Returns the number of stored precomputed distance.
protected  float getPrecomputedDistanceImpl(LocalAbstractObject obj)
          Implement this method to return the precomputed distance to an object.
protected  boolean includeUsingPrecompDistImpl(PrecomputedDistancesFilter targetFilter, float radius)
          Returns true if object associated with targetFilter filter can be included using this precomputed distances.
protected  boolean includeUsingPrecompDistImpl(PrecomputedDistancesFixedArrayFilter targetFilter, float radius)
          Returns true if object associated with targetFilter filter can be included using this precomputed distances.
 void insertPrecompDist(int pos, float dist)
          Insert distance into internal list of precomputed distances at the specified position.
 float insertPrecompDist(int pos, LocalAbstractObject p, LocalAbstractObject o)
          Insert distance into internal list of precomputed distances at the specified position.
protected  boolean isDataWritable()
          Returns whether this filter's data can be written to a text stream.
 boolean isGetterSupported()
          Returns true if this object supports PrecomputedDistancesFilter.getPrecomputedDistance(messif.objects.LocalAbstractObject) method.
 void removeLastPrecompDists(int cnt)
          Removes the requested number of distances from the end of the array.
 void removePrecompDist(int pos)
          Remove distance at the specified index from the internal list of precomputed distances.
 void resetAllPrecompDist()
          Removes all precomputed distances and sets the actual array size to zero (the maximal size stays).
protected  void resizePrecompDistArray(int newSize)
          Resize the internal precomputed distances array to the newSize.
 void setFixedPivotsPrecompDist(float[] precompDist)
          Replaces the current array of precomputed distances with the values passed in the argument.
 void setPrecompDist(int pos, float dist)
          Set distance in the internal list of precomputed distances at the specified position.
 float setPrecompDist(int pos, LocalAbstractObject p, LocalAbstractObject o)
          Set distance at the end of internal list of precomputed distances.
protected  void writeData(java.io.OutputStream stream)
          Store this filter's data to a text stream.
 
Methods inherited from class messif.objects.PrecomputedDistancesFilter
excludeUsingPrecompDist, getNextFilter, getPrecomputedDistance, includeUsingPrecompDist, write
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

precompDist

protected float[] precompDist
The list of precomputed distances


actualSize

protected int actualSize
The actual size of precompDist (if it was pre-buffered)

Constructor Detail

PrecomputedDistancesFixedArrayFilter

public PrecomputedDistancesFixedArrayFilter()
Creates a new instance of PrecomputedDistancesFixedArrayFilter.


PrecomputedDistancesFixedArrayFilter

public PrecomputedDistancesFixedArrayFilter(LocalAbstractObject object)
Creates a new instance of PrecomputedDistancesFixedArrayFilter.

Parameters:
object - the object to which to add this filter

PrecomputedDistancesFixedArrayFilter

public PrecomputedDistancesFixedArrayFilter(int initialSize)
Creates a new instance of PrecomputedDistancesFixedArrayFilter.

Parameters:
initialSize - the initial size for this filter's internal array of distances

PrecomputedDistancesFixedArrayFilter

public PrecomputedDistancesFixedArrayFilter(LocalAbstractObject object,
                                            int initialSize)
Creates a new instance of PrecomputedDistancesFixedArrayFilter

Parameters:
object - the object to which to add this filter
initialSize - the initial size for this filter's internal array of distances

PrecomputedDistancesFixedArrayFilter

public PrecomputedDistancesFixedArrayFilter(java.lang.String distancesString)
                                     throws java.lang.IllegalArgumentException
Creates a new instance of PrecomputedDistancesFixedArrayFilter from a string. The string must be of format "dist1 dist2 dist3...".

Parameters:
distancesString - string to create the filter from
Throws:
java.lang.IllegalArgumentException - if the string is of inappropriate format

PrecomputedDistancesFixedArrayFilter

protected PrecomputedDistancesFixedArrayFilter(BinaryInput input,
                                               BinarySerializator serializator)
                                        throws java.io.IOException
Creates a new instance of PrecomputedDistancesFixedArrayFilter loaded from binary input.

Parameters:
input - the input to read the PrecomputedDistancesFixedArrayFilter from
serializator - the serializator used to write objects
Throws:
java.io.IOException - if there was an I/O error reading from the input
Method Detail

isDataWritable

protected boolean isDataWritable()
Description copied from class: PrecomputedDistancesFilter
Returns whether this filter's data can be written to a text stream. Note that the method PrecomputedDistancesFilter.writeData(java.io.OutputStream) should provide a valid writing implementation.

Specified by:
isDataWritable in class PrecomputedDistancesFilter
Returns:
true if this filter can be written to a text stream

writeData

protected void writeData(java.io.OutputStream stream)
                  throws java.io.IOException
Description copied from class: PrecomputedDistancesFilter
Store this filter's data to a text stream. This method should have the opposite deserialization in constructor. Note that this method should not write a line separator (\n).

Specified by:
writeData in class PrecomputedDistancesFilter
Parameters:
stream - the stream to store this object to
Throws:
java.io.IOException - if there was an error while writing to stream

addPrecompDist

public int addPrecompDist(float dist)
Add distance at the end of internal list of precomputed distances.

Parameters:
dist - distance to append
Returns:
The total number of precomputed distances stored.

addPrecompDist

public int addPrecompDist(float[] dists)
Add the passed distances at the end of internal list of precomputed distances.

Parameters:
dists - array of distances to append
Returns:
The total number of precomputed distances stored.

addPrecompDist

public float addPrecompDist(LocalAbstractObject p,
                            LocalAbstractObject o)
Add distance at the end of internal list of precomputed distances. The distance is computed between the objects passed.

Parameters:
p - first object (usually pivot)
o - second object
Returns:
The distance computed between the object passed in arguments. The LocalAbstractObject.UNKNOWN_DISTANCE is returned if any of objects passed is null.

addPrecompDist

public int addPrecompDist(AbstractObjectList<LocalAbstractObject> pivots,
                          LocalAbstractObject obj)
Add distances at the end of internal list of precomputed distances. The distances appended are computed between all pivots passed in an iterator and the objects o. If pivots or o is null, no change is done.

Parameters:
pivots - list of objects (usually pivots)
obj - second object
Returns:
The total number of precomputed distances stored.

addPrecompDist

public int addPrecompDist(LocalAbstractObject[] pivots,
                          LocalAbstractObject obj)
Add distances at the end of internal list of precomputed distances. The distances appended are computed between all pivots passed in an iterator and the objects o. If pivots or o is null, no change is done.

Parameters:
pivots - list of objects (usually pivots)
obj - second object
Returns:
The total number of precomputed distances stored.

insertPrecompDist

public void insertPrecompDist(int pos,
                              float dist)
                       throws java.lang.IndexOutOfBoundsException
Insert distance into internal list of precomputed distances at the specified position.

Parameters:
pos - the index to insert the distance at
dist - the distance to insert
Throws:
java.lang.IndexOutOfBoundsException - is thrown when pos is out of bounds.

insertPrecompDist

public float insertPrecompDist(int pos,
                               LocalAbstractObject p,
                               LocalAbstractObject o)
                        throws java.lang.IndexOutOfBoundsException
Insert distance into internal list of precomputed distances at the specified position.

Parameters:
pos - the index to insert the distance at
p - first object (usually pivot)
o - second object
Returns:
The distance computed between the object passed in arguments. The LocalAbstractObject.UNKNOWN_DISTANCE is returned if any of objects passed is null.
Throws:
java.lang.IndexOutOfBoundsException - is thrown when pos is out of bounds.

setPrecompDist

public void setPrecompDist(int pos,
                           float dist)
                    throws java.lang.IndexOutOfBoundsException
Set distance in the internal list of precomputed distances at the specified position.

Parameters:
pos - the index to set the distance at
dist - the distance to set
Throws:
java.lang.IndexOutOfBoundsException - is thrown when pos is out of bounds.

setPrecompDist

public float setPrecompDist(int pos,
                            LocalAbstractObject p,
                            LocalAbstractObject o)
                     throws java.lang.IndexOutOfBoundsException
Set distance at the end of internal list of precomputed distances. The distance is computed between the objects passed.

Parameters:
pos - the index to insert the distance at
p - first object (usually pivot)
o - second object
Returns:
The distance computed between the object passed in arguments. The LocalAbstractObject.UNKNOWN_DISTANCE is returned if any of objects passed is null.
Throws:
java.lang.IndexOutOfBoundsException - is thrown when pos is out of bounds.

removePrecompDist

public void removePrecompDist(int pos)
                       throws java.lang.IndexOutOfBoundsException
Remove distance at the specified index from the internal list of precomputed distances. The elements behind the deleted index are shifted down and the array truncated.

Parameters:
pos - the index to remove the distance at
Throws:
java.lang.IndexOutOfBoundsException - is thrown when pos is out of bounds.

removeLastPrecompDists

public void removeLastPrecompDists(int cnt)
                            throws java.lang.IndexOutOfBoundsException
Removes the requested number of distances from the end of the array.

Parameters:
cnt - the number of distances to remove
Throws:
java.lang.IndexOutOfBoundsException - is thrown when the list of precomputed distance is already empty.

setFixedPivotsPrecompDist

public void setFixedPivotsPrecompDist(float[] precompDist)
Replaces the current array of precomputed distances with the values passed in the argument.

Parameters:
precompDist - an array of new distances

getPrecompDistSize

public int getPrecompDistSize()
Returns the number of stored precomputed distance.

Returns:
The size of array.

resetAllPrecompDist

public void resetAllPrecompDist()
Removes all precomputed distances and sets the actual array size to zero (the maximal size stays).


isGetterSupported

public boolean isGetterSupported()
Returns true if this object supports PrecomputedDistancesFilter.getPrecomputedDistance(messif.objects.LocalAbstractObject) method.

Specified by:
isGetterSupported in class PrecomputedDistancesFilter
Returns:
true if this object supports PrecomputedDistancesFilter.getPrecomputedDistance(messif.objects.LocalAbstractObject) method

getPrecompDist

public float getPrecompDist(int position)
Returns the precomputed distance at the specified index. If there is no distance associated with the index position the function returns LocalAbstractObject.UNKNOWN_DISTANCE.

Parameters:
position - the index to retrieve the distance from
Returns:
the precomputed distance at the specified index

getPrecompDist

public float[] getPrecompDist()
Return the whole array of precomputed distances.

Returns:
The whole array of precomputed distances is returned. null is returned if no precomputed distances are stored.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Creates and returns a copy of this object.

Overrides:
clone in class PrecomputedDistancesFilter
Returns:
a copy of this object
Throws:
java.lang.CloneNotSupportedException - if this object cannot be cloned.

excludeUsingPrecompDistImpl

protected final boolean excludeUsingPrecompDistImpl(PrecomputedDistancesFilter targetFilter,
                                                    float radius)
Description copied from class: PrecomputedDistancesFilter
Returns true if object associated with targetFilter filter can be excluded (filtered out) using this precomputed distances. See LocalAbstractObject.excludeUsingPrecompDist(messif.objects.LocalAbstractObject, float) for full explanation.

Specified by:
excludeUsingPrecompDistImpl in class PrecomputedDistancesFilter
Parameters:
targetFilter - the target precomputed distances
radius - the radius to check the precomputed distances for
Returns:
true if object associated with targetFilter filter can be excluded (filtered out) using this precomputed distances

excludeUsingPrecompDistImpl

protected boolean excludeUsingPrecompDistImpl(PrecomputedDistancesFixedArrayFilter targetFilter,
                                              float radius)
Return true if the obj has been filtered out using stored precomputed distance. Otherwise returns false, i.e. when obj must be checked using original distance (getDistance()). In other words, method returns true if this object and obj are more distant than radius. By analogy, returns false if this object and obj are within distance radius. However, both this cases use only precomputed distances! Thus, the real distance between this object and obj can be greater than radius although the method returned false!!!

Parameters:
targetFilter - the target precomputed distances
radius - the radius to check the precomputed distances for
Returns:
true if object associated with targetFilter filter can be excluded (filtered out) using this precomputed distances

includeUsingPrecompDistImpl

protected final boolean includeUsingPrecompDistImpl(PrecomputedDistancesFilter targetFilter,
                                                    float radius)
Description copied from class: PrecomputedDistancesFilter
Returns true if object associated with targetFilter filter can be included using this precomputed distances. See LocalAbstractObject.includeUsingPrecompDist(messif.objects.LocalAbstractObject, float) for full explanation.

Specified by:
includeUsingPrecompDistImpl in class PrecomputedDistancesFilter
Parameters:
targetFilter - the target precomputed distances
radius - the radius to check the precomputed distances for
Returns:
true if object associated with targetFilter filter can be included using this precomputed distances

includeUsingPrecompDistImpl

protected boolean includeUsingPrecompDistImpl(PrecomputedDistancesFixedArrayFilter targetFilter,
                                              float radius)
Returns true if object associated with targetFilter filter can be included using this precomputed distances. See LocalAbstractObject.includeUsingPrecompDist(messif.objects.LocalAbstractObject, float) for full explanation.

Parameters:
targetFilter - the target precomputed distances
radius - the radius to check the precomputed distances for
Returns:
true if object associated with targetFilter filter can be included using this precomputed distances

getPrecomputedDistanceImpl

protected float getPrecomputedDistanceImpl(LocalAbstractObject obj)
Description copied from class: PrecomputedDistancesFilter
Implement this method to return the precomputed distance to an object. If there is no distance associated with the object obj the function should return UNKNOWN_DISTANCE.

Specified by:
getPrecomputedDistanceImpl in class PrecomputedDistancesFilter
Parameters:
obj - the object for which the precomputed distance is returned
Returns:
the precomputed distance to an object

resizePrecompDistArray

protected void resizePrecompDistArray(int newSize)
Resize the internal precomputed distances array to the newSize. The array can only be enlarged, i.e., the array cannot be truncated by calling this method.

Parameters:
newSize - the new size for the precomputed array

binarySerialize

public int binarySerialize(BinaryOutput output,
                           BinarySerializator serializator)
                    throws java.io.IOException
Binary-serialize this object into the output.

Specified by:
binarySerialize in interface BinarySerializable
Overrides:
binarySerialize in class PrecomputedDistancesFilter
Parameters:
output - the output that this object is binary-serialized into
serializator - the serializator used to write objects
Returns:
the number of bytes actually written
Throws:
java.io.IOException - if there was an I/O error during serialization

getBinarySize

public int getBinarySize(BinarySerializator serializator)
Returns the exact size of the binary-serialized version of this object in bytes.

Specified by:
getBinarySize in interface BinarySerializable
Overrides:
getBinarySize in class PrecomputedDistancesFilter
Parameters:
serializator - the serializator used to write objects
Returns:
size of the binary-serialized version of this object