Class PriorityQ<T>
- java.lang.Object
-
- com.googlecode.javaewah.datastructure.PriorityQ<T>
-
- Type Parameters:
T
- object type
public final class PriorityQ<T> extends Object
Special-purpose priority queue. Does limited error checking and supports toss, buildHeap, poll, peek, percolateDown. It is faster than the equivalent class from java.util.- Since:
- 0.8.0
- Author:
- Owen Kaser
-
-
Constructor Summary
Constructors Constructor Description PriorityQ(int maxSize, Comparator<T> c)
Construct a priority queue with a given capacity
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
buildHeap()
build the heap...boolean
isEmpty()
Check whether the heap is empty.T
peek()
Look at the top of the heapvoid
percolateDown()
Signals that the element on top of the heap has been updatedT
poll()
Remove the element on top of the heapint
size()
void
toss(T t)
Add an element at the end of the queue
-
-
-
Constructor Detail
-
PriorityQ
public PriorityQ(int maxSize, Comparator<T> c)
Construct a priority queue with a given capacity- Parameters:
maxSize
- capacityc
- comparator
-
-
Method Detail
-
size
public int size()
- Returns:
- the size of the queue
-
toss
public void toss(T t)
Add an element at the end of the queue- Parameters:
t
- element to be added
-
peek
public T peek()
Look at the top of the heap- Returns:
- the element on top
-
buildHeap
public void buildHeap()
build the heap...
-
percolateDown
public void percolateDown()
Signals that the element on top of the heap has been updated
-
poll
public T poll()
Remove the element on top of the heap- Returns:
- the element being removed
-
isEmpty
public boolean isEmpty()
Check whether the heap is empty.- Returns:
- true if empty
-
-