public class HashBackedPriorityQueue extends java.lang.Object implements Queue
Modifier and Type | Field and Description |
---|---|
protected ReplayAlgorithm |
algorithm |
protected gnu.trove.map.hash.TIntIntHashMap |
locationMap |
protected int |
maxCost
The maximum total cost for any record in this queue.
|
protected static int |
NEV |
protected int[] |
queue
Priority queue represented as a balanced binary heap: the two children of
queue[n] are queue[2*n+1] and queue[2*(n+1)].
|
protected int |
size
The number of elements in the priority queue.
|
Constructor and Description |
---|
HashBackedPriorityQueue(ReplayAlgorithm algorithm,
int initialCapacity) |
HashBackedPriorityQueue(ReplayAlgorithm algorithm,
int initialCapacity,
int maxCost) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(int marking)
Inserts the specified element into this priority queue.
|
boolean |
checkInv()
Debugging method that checks the queue invariant on the queue
|
protected boolean |
checkInv(int loc) |
boolean |
contains(int marking)
Checks if the the stored marking with ID markingId is contained in this
queue.
|
ReplayAlgorithm |
getAlgorithm()
Return the algorithm for which this Queue is used.
|
long |
getEstimatedMemorySize()
returns the maximum memory use in bytes the queue ever had.
|
int |
getMaxCost() |
protected void |
grow(int minCapacity)
Increases the capacity of the array.
|
int |
hashCode() |
protected boolean |
isBetter(int marking1,
int marking2)
First order sorting is based on F score alone.
|
boolean |
isEmpty()
returns true if the queue is empty
|
int |
maxCapacity()
returns the maximum memory capacity the queue ever had.
|
int |
maxSize()
returns maximum number of elements the queue ever contained.
|
protected void |
offer(int marking)
Inserts the specified element into this priority queue.
|
int |
peek()
Show the number of the marking at the head of the priority queue
|
protected int |
peek(int location) |
int |
poll()
remove and return the head of the queue
|
void |
setMaxCost(int maxCost) |
protected void |
siftDown(int positionToFill,
int marking)
Inserts item x at position k, maintaining heap invariant by demoting x down
the tree repeatedly until it is less than or equal to its children or is a
leaf.
|
protected void |
siftUp(int fromPosition,
int marking)
Inserts item x at position k, maintaining heap invariant by promoting x up
the tree until it is greater than or equal to its parent, or is the root.
|
int |
size()
Returns the current number of elements in the queue
|
java.lang.String |
toString() |
protected final ReplayAlgorithm algorithm
protected final gnu.trove.map.hash.TIntIntHashMap locationMap
protected static final int NEV
protected int[] queue
protected int size
protected int maxCost
public HashBackedPriorityQueue(ReplayAlgorithm algorithm, int initialCapacity)
public HashBackedPriorityQueue(ReplayAlgorithm algorithm, int initialCapacity, int maxCost)
public ReplayAlgorithm getAlgorithm()
Queue
getAlgorithm
in interface Queue
public boolean isEmpty()
Queue
public int hashCode()
hashCode
in class java.lang.Object
public void setMaxCost(int maxCost)
public int getMaxCost()
public boolean contains(int marking)
Queue
public boolean checkInv()
Queue
protected void grow(int minCapacity)
minCapacity
- the desired minimum capacitypublic int peek()
Queue
public int size()
Queue
public int poll()
Queue
protected int peek(int location)
public java.lang.String toString()
toString
in class java.lang.Object
public boolean add(int marking)
add
in interface Queue
true
(as specified by Collection.add(E)
)java.lang.ClassCastException
- if the specified element cannot be compared with elements
currently in this priority queue according to the priority
queue's orderingjava.lang.NullPointerException
- if the specified element is nullprotected boolean isBetter(int marking1, int marking2)
protected void offer(int marking)
java.lang.ClassCastException
- if the specified element cannot be compared with elements
currently in this priority queue according to the priority
queue's orderingjava.lang.NullPointerException
- if the specified element is nullprotected void siftUp(int fromPosition, int marking)
fromPosition
- marking
- the item to insertprotected void siftDown(int positionToFill, int marking)
positionToFill
- the position to fillmarking
- the item to insertprotected boolean checkInv(int loc)
public int maxCapacity()
Queue
maxCapacity
in interface Queue
public int maxSize()
Queue
public long getEstimatedMemorySize()
Queue
getEstimatedMemorySize
in interface Queue