messif.objects
Class PrecomputedDistancesPivotMapFilter

java.lang.Object
  extended by messif.objects.PrecomputedDistancesFilter
      extended by messif.objects.PrecomputedDistancesPivotMapFilter
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, BinarySerializable

public class PrecomputedDistancesPivotMapFilter
extends PrecomputedDistancesFilter

Precomputed distance filter that has the stored precomputed distances mapped to the respective LocalAbstractObject. While filtering, this filter uses one stored distance against the respective object from the map. Note that this filter should not be used when the instances of referenced objects are not in memory. Moreover, this filter cannot be written to text stream, since the reference objects cannot be correctly resolved. However, a java serialization or binary serialization can be used.

See Also:
Serialized Form

Field Summary
protected  java.util.Map<LocalAbstractObject,java.lang.Float> precompDistMapping
          The hash table of precomputed distances
 
Fields inherited from class messif.objects.PrecomputedDistancesFilter
counterPrecomputedDistanceSavings
 
Constructor Summary
  PrecomputedDistancesPivotMapFilter()
          Creates a new instance of PrecomputedDistancesPivotMapFilter
protected PrecomputedDistancesPivotMapFilter(BinaryInput input, BinarySerializator serializator)
          Creates a new instance of PrecomputedDistancesPivotMapFilter loaded from binary input.
  PrecomputedDistancesPivotMapFilter(LocalAbstractObject object)
          Creates a new instance of PrecomputedDistancesPivotMapFilter
 
Method Summary
 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(PrecomputedDistancesPivotMapFilter 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.
 int getPrecompDistSize()
          Returns the number of stored precomputed distances.
 java.util.Set<LocalAbstractObject> getPrecompObjects()
          Return all objects to which this object has precomputed distances.
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(PrecomputedDistancesPivotMapFilter targetFilter, float radius)
          Returns true if object associated with targetFilter filter can be included using this precomputed distances.
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 resetAllPrecompDist()
          Removes all precomputed distances.
 boolean resetPrecompDist(LocalAbstractObject obj)
          Resets the precomputed distance to given object (pivot).
 boolean setPrecompDist(LocalAbstractObject obj, float dist)
          Associates a precomputed distance to an object with this object Function appends the new distance 'dist' from the object 'obj' or replaces the old value of distance.
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

precompDistMapping

protected final java.util.Map<LocalAbstractObject,java.lang.Float> precompDistMapping
The hash table of precomputed distances

Constructor Detail

PrecomputedDistancesPivotMapFilter

public PrecomputedDistancesPivotMapFilter()
Creates a new instance of PrecomputedDistancesPivotMapFilter


PrecomputedDistancesPivotMapFilter

public PrecomputedDistancesPivotMapFilter(LocalAbstractObject object)
Creates a new instance of PrecomputedDistancesPivotMapFilter

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

PrecomputedDistancesPivotMapFilter

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

Parameters:
input - the input to read the PrecomputedDistancesPivotMapFilter 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

setPrecompDist

public boolean setPrecompDist(LocalAbstractObject obj,
                              float dist)
Associates a precomputed distance to an object with this object Function appends the new distance 'dist' from the object 'obj' or replaces the old value of distance. If 'dist == LocalAbstractObject.UNKNOWN_DISTANCE' then the precomputed distance is removed. Note that no distance computation is done.

Parameters:
obj - the object for which to add distance
dist - the distance to add
Returns:
If there is no distance associated with the object obj the function returns false. Otherwise, returns true.

resetPrecompDist

public boolean resetPrecompDist(LocalAbstractObject obj)
Resets the precomputed distance to given object (pivot).

Parameters:
obj - Object to which the precomputed distance is stored.
Returns:
If there is no distance associated with the object obj the function returns false. Otherwise, returns true.

resetAllPrecompDist

public void resetAllPrecompDist()
Removes all precomputed distances.


getPrecompDistSize

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

Returns:
the number of stored precomputed distances

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(PrecomputedDistancesPivotMapFilter 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(PrecomputedDistancesPivotMapFilter 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

isGetterSupported

public boolean isGetterSupported()
Description copied from class: PrecomputedDistancesFilter
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

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

getPrecompObjects

public java.util.Set<LocalAbstractObject> getPrecompObjects()
Return all objects to which this object has precomputed distances.

Returns:
all objects to which this object has precomputed distances

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Description copied from class: PrecomputedDistancesFilter
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.

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