Package repast.simphony.util
Class PriorityQueue<T>
java.lang.Object
repast.simphony.util.PriorityQueue<T>
A priority queue where the items are ordered according to a
specified comparator.
This priority queue uses a binary heap algorithm as described in Mark Allen Weis,
_Algorithms, Data Structures, and Problem Solving with C++_, chapter 20.
- Version:
- $Revision: 1.1 $ $Date: 2005/12/21 22:25:34 $
- Author:
- Nick Collier
-
Constructor Summary
ConstructorDescriptionPriorityQueue
(T minValue, Comparator<T> comp) Creates a PriorityQueue with a default initial size of 13.PriorityQueue
(T minValue, Comparator<T> comp, int size) Creates a PriorityQueue with the specified initial size. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Removes all elements from the queue.void
fixHeap()
Reinstate the heap order.void
Insert the specified item into the queue.boolean
isEmpty()
Returns true if the queue is empty, otherwise false.peekMin()
Get the minimum element from the queque without removing it from the queue.popMin()
Remove the minimum element from the queque and return it.int
size()
Gets the number of elements in the queue.void
Insert the specified item into the queue without maintain heap order.
-
Constructor Details
-
PriorityQueue
Creates a PriorityQueue with a default initial size of 13. The minValue param is expected to less than any value put in the queue.- Parameters:
minValue
- the absolute minimum value put in the queue.comp
- the comparator used to order the items in the queue.
-
PriorityQueue
Creates a PriorityQueue with the specified initial size. The minValue param is expected to less than any value put in the queue.- Parameters:
minValue
- the absolute minimum value put in the queue.comp
- the comparator used to order the items in the queue.size
- the intial size of the queue
-
-
Method Details
-
insert
Insert the specified item into the queue. -
peekMin
Get the minimum element from the queque without removing it from the queue. If heap order is not currently correct, the heap will be fixed before the minimum is returned.- Returns:
- the minimum element from the queque
-
popMin
Remove the minimum element from the queque and return it. If heap order is not currently correct, the heap will be fixed before the minimum is returned.- Returns:
- the minimum element from the queque
-
toss
Insert the specified item into the queue without maintain heap order.- Parameters:
obj
- the item to insert into the queue
-
clear
public void clear()Removes all elements from the queue. -
fixHeap
public void fixHeap()Reinstate the heap order. This will fix the tree, ordering it correctly. -
isEmpty
public boolean isEmpty()Returns true if the queue is empty, otherwise false.- Returns:
- true if the queue is empty, otherwise false.
-
size
public int size()Gets the number of elements in the queue.- Returns:
- the number of elements in the queue.
-