net.obsearch.result
Class OBPriorityQueueInvertedDouble<O>

java.lang.Object
  extended by net.obsearch.AbstractOBPriorityQueue<OBResultInvertedDouble<O>>
      extended by net.obsearch.result.OBPriorityQueueInvertedDouble<O>
All Implemented Interfaces:
Iterable<OBResultInvertedDouble<O>>

public final class OBPriorityQueueInvertedDouble<O>
extends AbstractOBPriorityQueue<OBResultInvertedDouble<O>>

This is a class used to efficiently perform k-nn searches. This queue is meant to be used with objects OBDouble. Inverted results will put first smaller values in the priority queue.

Since:
0.7
Author:
Arnoldo Jose Muller Molina

Field Summary
 
Fields inherited from class net.obsearch.AbstractOBPriorityQueue
k, queue
 
Constructor Summary
OBPriorityQueueInvertedDouble(int k)
          Create the priority queue with k elements.
 
Method Summary
 boolean add(long id, O obj, double distance)
          Add the given object, object id and distance of type double to the queue.
 void addMax(long id, O obj, double distance)
          Add the given object, object id and distance of type double to the queue.
 boolean isCandidate(double d)
          Returns true if the given distance can be a candidate for adding it into the queue.
 double updateRange(double r)
          If queue.size() == k, then if the user's range is greater than the greatest element of the queue, we can reduce the range to the biggest element of the priority queue, that is its queue.peek() element.
 
Methods inherited from class net.obsearch.AbstractOBPriorityQueue
equals, getK, getSize, getSortedElements, isFull, iterator, peek, poll, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OBPriorityQueueInvertedDouble

public OBPriorityQueueInvertedDouble(int k)
Create the priority queue with k elements. This is how you set the k for a query. Use a negative value for a boundless queue.

Method Detail

add

public boolean add(long id,
                   O obj,
                   double distance)
            throws InstantiationException,
                   IllegalAccessException
Add the given object, object id and distance of type double to the queue. This method tries to minimize the sizes of distances of the priority queue.

Parameters:
id - The id of the object to be used
obj - The object to be added
distance - The distance to be added
Returns:
true if the range has changed.
Throws:
IllegalAccessException - If there is a problem when instantiating objects O
InstantiationException - If there is a problem when instantiating objects O

addMax

public void addMax(long id,
                   O obj,
                   double distance)
            throws InstantiationException,
                   IllegalAccessException
Add the given object, object id and distance of type double to the queue. This method tries to maximize the sizes of distances of the priority queue.

Parameters:
id - The id of the object to be used
obj - The object to be added
distance - The distance to be added
Throws:
IllegalAccessException - If there is a problem when instantiating objects O
InstantiationException - If there is a problem when instantiating objects O

updateRange

public double updateRange(double r)
If queue.size() == k, then if the user's range is greater than the greatest element of the queue, we can reduce the range to the biggest element of the priority queue, that is its queue.peek() element.

Parameters:
r - The new range we want to calculate.
Returns:
the new range or the old range if the above condition is not met

isCandidate

public boolean isCandidate(double d)
Returns true if the given distance can be a candidate for adding it into the queue. The parameter d is an estimation of the real distance, and this method is used to decide if we should calculate the real distance.

Parameters:
d - The lower resolution distance.
Returns:
True if we should calculate the real distance and attempt add the corresponding object into this queue.


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