ostore.util
Class PriorityQueue

java.lang.Object
  |
  +--ostore.util.PriorityQueue

public class PriorityQueue
extends Object

PriorityQueue is a (blocking) priority queue. One of these will be used to store updates (and it will be read by the update thread) and the other stores query/success/fail messages for the location algorithm thread. Objects with small priorities come out first.

Version:
$Id: PriorityQueue.java,v 1.7 2003/04/24 23:38:56 strib Exp $
Author:
Westley Weimer

Field Summary
static boolean DEBUG
           
 
Constructor Summary
PriorityQueue(int initial_capacity)
          The constructor creates a new priority queue.
 
Method Summary
 int capacity()
          returns the current capacity of the heap.
 boolean check()
           
 boolean empty()
          returns the number of objects currently in the queue (0 means empty).
 Object extract(boolean blocking)
          extract() returns the object with the smallest priority in the queue and removes it from the queue.
 boolean insert(Object o, long prio, boolean blocking)
          inserts an object with the given priority.
 int maxSize()
          returns the maximum size of the heap.
 void print(int n)
           
 void printPrios()
           
 boolean remove(Object o)
          removes the given object from the priority queue. returns true if the object was found and removed, false otherwise.
 boolean removeAll(Object o)
          removes every instance the given object from the priority queue.
 int size()
          returns the number of objects currently in the queue (0 means empty).
 Object topObject(boolean blocking)
          topObject() returns the smallest priority object in the queue, or null if the queue is empty and blocking is not set.
 long topPriority(boolean blocking)
          topPriority() returns the smallest priority in the queue, or 0 if the queue is empty and blocking is not set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static final boolean DEBUG
See Also:
Constant Field Values
Constructor Detail

PriorityQueue

public PriorityQueue(int initial_capacity)
The constructor creates a new priority queue.

Parameters:
initial_capacity - the initial capacity of the heap.
Method Detail

size

public int size()
returns the number of objects currently in the queue (0 means empty).


empty

public boolean empty()
returns the number of objects currently in the queue (0 means empty).


maxSize

public int maxSize()
returns the maximum size of the heap.


capacity

public int capacity()
returns the current capacity of the heap.


insert

public boolean insert(Object o,
                      long prio,
                      boolean blocking)
inserts an object with the given priority. If the queue is full, the internal storage arrays are doubled in a very naive way.

Parameters:
blocking - ignored.

remove

public boolean remove(Object o)
removes the given object from the priority queue. returns true if the object was found and removed, false otherwise.


removeAll

public boolean removeAll(Object o)
removes every instance the given object from the priority queue. returns true if the object was found and removed, false otherwise.


topPriority

public long topPriority(boolean blocking)
topPriority() returns the smallest priority in the queue, or 0 if the queue is empty and blocking is not set.


topObject

public Object topObject(boolean blocking)
topObject() returns the smallest priority object in the queue, or null if the queue is empty and blocking is not set.


extract

public Object extract(boolean blocking)
extract() returns the object with the smallest priority in the queue and removes it from the queue. If the queue is empty and blocking is set, this operation blocks. If the queue is empty and blocking is not set, null is returned.


check

public boolean check()

print

public void print(int n)

printPrios

public void printPrios()