com.googlecode.javaewah.datastructure
Class PriorityQ<T>

java.lang.Object
  extended by 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
PriorityQ(int maxSize, Comparator<T> c)
          Construct a priority queue with a given capacity
 
Method Summary
 void buildHeap()
          build the heap...
 boolean isEmpty()
          Check whether the heap is empty.
 T peek()
          Look at the top of the heap
 void percolateDown()
          Signals that the element on top of the heap has been updated
 T poll()
          Remove the element on top of the heap
 int size()
           
 void toss(T t)
          Add an element at the end of the queue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PriorityQ

public PriorityQ(int maxSize,
                 Comparator<T> c)
Construct a priority queue with a given capacity

Parameters:
maxSize - capacity
c - 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


Copyright © 2014. All Rights Reserved.