T - any Java objectpublic class HashIndexedHeap<T>
extends java.lang.Object
implements java.lang.Iterable<T>
By default, the heap is a max heap (which results in elements with the highest priority being dequeued first), but it may also be set to be a min heap.
| Modifier and Type | Field and Description | 
|---|---|
protected java.util.Map<T,java.lang.Integer> | 
arrayIndexMap
Hash map from objects to their index in the heap 
 | 
protected boolean | 
maxHeap
If true, this is ordered according to a max heap; if false ordered according to a min heap. 
 | 
protected java.util.List<T> | 
nodesArray
Heap ordered list of objects 
 | 
protected java.util.Comparator<T> | 
priorityCompare
A comparator to compare objects 
 | 
protected int | 
size
Number of objects in the heap 
 | 
| Constructor and Description | 
|---|
HashIndexedHeap(java.util.Comparator<T> pcompare)
Initializes the heap with a comparator 
 | 
HashIndexedHeap(java.util.Comparator<T> pcompare,
               int capacity)
Initializes the heap with a comparator and an initial capacity size 
 | 
| Modifier and Type | Method and Description | 
|---|---|
T | 
containsInstance(T inst)
Checks if the heap contains this object and returns the pointer to the stored object if it does; otherwise null is returned. 
 | 
void | 
insert(T el)
Inserts the element into the heap 
 | 
java.util.Iterator<T> | 
iterator()  | 
T | 
peek()
Returns a pointer to the head of the heap without removing it 
 | 
T | 
poll()
Returns a pointer to the head of the heap and removes it 
 | 
void | 
refreshPriority(T el)
Calling this method indicates that the priority of the object passed to the method has been modified and that this heap needs to reorder its elements
 as a result 
 | 
boolean | 
satisifiesHeap()
This method returns whether the data structure stored is in fact a heap (costs linear time). 
 | 
void | 
setUseMaxHeap(boolean max)
Sets whether this heap is a max heap or a min heap 
 | 
int | 
size()
Returns the size of the heap 
 | 
protected java.util.List<T> nodesArray
protected int size
protected java.util.Map<T,java.lang.Integer> arrayIndexMap
protected boolean maxHeap
protected java.util.Comparator<T> priorityCompare
public HashIndexedHeap(java.util.Comparator<T> pcompare)
pcompare - the comparator to compare the priority of elements of this heappublic HashIndexedHeap(java.util.Comparator<T> pcompare, int capacity)
pcompare - the comparator to compare the priority of elements of this heapcapacity - the initial compacity size of the heappublic int size()
public void setUseMaxHeap(boolean max)
max - if true, sets to be ma heap; if false sets to be min heap.public T containsInstance(T inst)
inst - the inst to look for in the heappublic T peek()
public T poll()
public void insert(T el)
el - the element to be insertedpublic void refreshPriority(T el)
el - the element whose priority was modifiedpublic java.util.Iterator<T> iterator()
iterator in interface java.lang.Iterable<T>public boolean satisifiesHeap()