net.obsearch.result
Class OBPriorityQueueLong<O>

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

public final class OBPriorityQueueLong<O>
extends AbstractOBPriorityQueue<OBResultLong<O>>

This is a class used to efficiently perform k-nn searches. This queue is meant to be used with objects OBLong.

Since:
0.7
Author:
Arnoldo Jose Muller Molina

Field Summary
 
Fields inherited from class net.obsearch.AbstractOBPriorityQueue
k, queue
 
Constructor Summary
OBPriorityQueueLong(int k)
          Create the priority queue with k elements.
 
Method Summary
 boolean add(long id, O obj, long distance)
          Add the given object, object id and distance of type long to the queue.
 void addMax(long id, O obj, long distance)
          Add the given object, object id and distance of type long to the queue.
 boolean isCandidate(long d)
          Returns true if the given distance can be a candidate for adding it into the queue.
 long updateRange(long 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

OBPriorityQueueLong

public OBPriorityQueueLong(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,
                   long distance)
            throws InstantiationException,
                   IllegalAccessException
Add the given object, object id and distance of type long 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,
                   long distance)
            throws InstantiationException,
                   IllegalAccessException
Add the given object, object id and distance of type long 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 long updateRange(long 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(long 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.