ostore.introspect
Class SemanticDistanceModel.BoundedPrioQueue

java.lang.Object
  |
  +--ostore.introspect.SemanticDistanceModel.BoundedPrioQueue
All Implemented Interfaces:
QuickSerializable
Enclosing class:
SemanticDistanceModel

public static class SemanticDistanceModel.BoundedPrioQueue
extends Object
implements QuickSerializable

Implementation of a priority queue of tuples (sorted by priority) which throws away stuff at the end when it gets larger than bound.

This is an internal class. Do not use outside SemanticDistanceModel.


Nested Class Summary
static class SemanticDistanceModel.BoundedPrioQueue.TupleComparator
           
 
Constructor Summary
SemanticDistanceModel.BoundedPrioQueue(InputBuffer buffer)
           
SemanticDistanceModel.BoundedPrioQueue(int initBound)
          New bounded prio queue
 
Method Summary
 int getBound()
          Get the max number of elements allowed in the queue.
 Distance getDistance(QuickSerializable to)
          Get the distance value to type to.
 SemanticDistanceModel.Tuple getTuple(QuickSerializable key)
          Get the tuple to type key
 Iterator iterator()
          Iterator of tuples in ascending order.
 SemanticDistanceModel.Tuple remove(QuickSerializable key)
          Remove a tuple.
 void removeLast()
          Remove the last element in the prio queue
 void serialize(OutputBuffer buffer)
          Add the object to the buffer.
 void setBound(int bound)
          Set the max number of elements allowed in the queue.
 int size()
          Number of elements in the queue
 String toString()
          Warning: this method runs in O(n) time.
 boolean update(SemanticDistanceModel.Tuple tuple)
          Update (or add) the tuple <t,d,num>.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SemanticDistanceModel.BoundedPrioQueue

public SemanticDistanceModel.BoundedPrioQueue(int initBound)
New bounded prio queue

Parameters:
initBound - the intial bound on the number of elements

SemanticDistanceModel.BoundedPrioQueue

public SemanticDistanceModel.BoundedPrioQueue(InputBuffer buffer)
                                       throws QSException
Method Detail

serialize

public void serialize(OutputBuffer buffer)
Description copied from interface: QuickSerializable
Add the object to the buffer.

Specified by:
serialize in interface QuickSerializable
Parameters:
buffer - the output buffer to add the object to

setBound

public void setBound(int bound)
Set the max number of elements allowed in the queue.


getBound

public int getBound()
Get the max number of elements allowed in the queue.


update

public boolean update(SemanticDistanceModel.Tuple tuple)
Update (or add) the tuple <t,d,num>.

FIXME: Java's fucking stupid TreeSet implementation has no removeLast/update function, so you MUST remove the tuple from the queue first, then update it, then add it again using this method.

Parameters:
tuple - the tuple to update (add if not already in the queue)
Returns:
true if the update resulted in some tuple being removed from the end of the prio queue.

getTuple

public SemanticDistanceModel.Tuple getTuple(QuickSerializable key)
Get the tuple to type key


remove

public SemanticDistanceModel.Tuple remove(QuickSerializable key)
Remove a tuple.


getDistance

public Distance getDistance(QuickSerializable to)
Get the distance value to type to. Null if it is not in the prio queue.


iterator

public Iterator iterator()
Iterator of tuples in ascending order.


size

public int size()
Number of elements in the queue


removeLast

public void removeLast()
Remove the last element in the prio queue


toString

public String toString()
Warning: this method runs in O(n) time.

Overrides:
toString in class Object