Top Description Fields Constructors Methods
com.googlecode.javaewah.datastructure

public final Class PriorityQ<T>

extends Object
Class Inheritance
Type Parameters
<T>
object type
Imports
java.util.Comparator

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.
Author
Owen Kaser
Since
0.8.0

Field Summary

Modifier and TypeField and Description
pack-priv final T[]
a

pack-priv final Comparator<T>
pack-priv int

Constructor Summary

AccessConstructor and Description
public
PriorityQ(final int
capacity
maxSize
,
final Comparator<T>
comparator
c
)

Construct a priority queue with a given capacity

Method Summary

Modifier and TypeMethod and Description
public void
buildHeap()

build the heap...

private int
compare(T a, T b)

public boolean

Returns:

true if empty
isEmpty
()

Check whether the heap is empty.

public T

Returns:

the element on top
peek
()

Look at the top of the heap

public void
percolateDown()

Signals that the element on top of the heap has been updated

private void
public T

Returns:

the element being removed
poll
()

Remove the element on top of the heap

public int

Returns:

the size of the queue
size
()

public void
toss(final T
element to be added
t
)

Add an element at the end of the queue

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aback to summary
pack-priv final T[] a
compback to summary
pack-priv final Comparator<T> comp
lastIndexback to summary
pack-priv int lastIndex

Constructor Detail

PriorityQback to summary
public PriorityQ(final int maxSize, final Comparator<T> c)

Construct a priority queue with a given capacity

Parameters
maxSize:int

capacity

c:Comparator<T>

comparator

Annotations
@SuppressWarnings:unchecked

Method Detail

buildHeapback to summary
public void buildHeap()

build the heap...

compareback to summary
private int compare(T a, T b)
isEmptyback to summary
public boolean isEmpty()

Check whether the heap is empty.

Returns:boolean

true if empty

peekback to summary
public T peek()

Look at the top of the heap

Returns:T

the element on top

percolateDownback to summary
public void percolateDown()

Signals that the element on top of the heap has been updated

percolateDownback to summary
private void percolateDown(int i)
pollback to summary
public T poll()

Remove the element on top of the heap

Returns:T

the element being removed

sizeback to summary
public int size()
Returns:int

the size of the queue

tossback to summary
public void toss(final T t)

Add an element at the end of the queue

Parameters
t:T

element to be added