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 Details

    • PriorityQ

      public PriorityQ(int maxSize, Comparator<T> c)
      Construct a priority queue with a given capacity
      Parameters:
      maxSize - capacity
      c - comparator
  • Method Details

    • 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