EDU.oswego.cs.dl.util.concurrent
public class: BoundedPriorityQueue [javadoc |
source]
java.lang.Object
EDU.oswego.cs.dl.util.concurrent.SemaphoreControlledChannel
EDU.oswego.cs.dl.util.concurrent.BoundedPriorityQueue
All Implemented Interfaces:
BoundedChannel
A heap-based priority queue, using semaphores for
concurrency control.
The take operation returns the
least element
with respect to the given ordering. (If more than
one element is tied for least value, one of them is
arbitrarily chosen to be returned -- no guarantees
are made for ordering across ties.)
Ordering follows the JDK1.2 collection
conventions: Either the elements must be Comparable, or
a Comparator must be supplied. Comparison failures throw
ClassCastExceptions during insertions and extractions.
The implementation uses a standard array-based heap algorithm,
as described in just about any data structures textbook.
Put and take operations may throw ClassCastException
if elements are not Comparable, or
not comparable using the supplied comparator.
Since not all elements are compared on each operation
it is possible that an exception will not be thrown
during insertion of non-comparable element, but will later be
encountered during another insertion or extraction.
[ Introduction to this package. ]
Field Summary |
---|
protected final Heap | heap_ | |
Constructor: |
public BoundedPriorityQueue() {
this(DefaultChannelCapacity.get(), null);
}
Create a priority queue with the current default capacity
and relying on natural ordering.
* |
public BoundedPriorityQueue(Comparator comparator) {
this(DefaultChannelCapacity.get(), comparator);
}
Create a priority queue with the current default capacity
and the given comparator
* |
public BoundedPriorityQueue(int capacity) {
this(capacity, null);
}
Create a priority queue with the given capacity,
and relying on natural ordering.
* |
public BoundedPriorityQueue(int capacity,
Comparator cmp) throws IllegalArgumentException {
super(capacity);
heap_ = new Heap(capacity, cmp);
}
Create a priority queue with the given capacity and comparator Throws:
IllegalArgumentException - if capacity less or equal to zero
- exception:
IllegalArgumentException - if capacity less or equal to zero
|
public BoundedPriorityQueue(int capacity,
Comparator cmp,
Class semaphoreClass) throws IllegalArgumentException, NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException {
super(capacity, semaphoreClass);
heap_ = new Heap(capacity, cmp);
}
Create a priority queue with the given capacity and comparator, using
the supplied Semaphore class for semaphores. Throws:
IllegalArgumentException - if capacity less or equal to zero
NoSuchMethodException - If class does not have constructor
that intializes permits
SecurityException - if constructor information
not accessible
InstantiationException - if semaphore class is abstract
IllegalAccessException - if constructor cannot be called
InvocationTargetException - if semaphore constructor throws an
exception
- exception:
IllegalArgumentException - if capacity less or equal to zero
- exception:
NoSuchMethodException - If class does not have constructor
that intializes permits
- exception:
SecurityException - if constructor information
not accessible
- exception:
InstantiationException - if semaphore class is abstract
- exception:
IllegalAccessException - if constructor cannot be called
- exception:
InvocationTargetException - if semaphore constructor throws an
exception
|
Method from EDU.oswego.cs.dl.util.concurrent.BoundedPriorityQueue Summary: |
---|
extract, insert, peek |
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from EDU.oswego.cs.dl.util.concurrent.BoundedPriorityQueue Detail: |
protected Object extract() {
return heap_.extract();
}
|
protected void insert(Object x) {
heap_.insert(x);
}
|
public Object peek() {
return heap_.peek();
}
|