Package oracle.spatial.network.lod
Class BinaryHeap<E extends java.lang.Comparable>
- java.lang.Object
-
- oracle.spatial.network.lod.BinaryHeap<E>
-
- All Implemented Interfaces:
PriorityQueue<E>
public class BinaryHeap<E extends java.lang.Comparable> extends java.lang.Object implements PriorityQueue<E>
a binary Min. heap priority queue implementation Note the value has to implement the Comparable interface (int compareTo(Object obj) )
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceBinaryHeap.IndexKeeper<E>
-
Field Summary
Fields Modifier and Type Field Description protected static intDEFAULT_CAPACITYprotected java.lang.Object[]heapprotected BinaryHeap.IndexKeeperindexKeeperprotected intsize
-
Constructor Summary
Constructors Constructor Description BinaryHeap()BinaryHeap(boolean isMinHeap)BinaryHeap(int initialCapacity)BinaryHeap(int initialCapacity, boolean isMinHeap)BinaryHeap(int initialCapacity, BinaryHeap.IndexKeeper indexKeeper)BinaryHeap(int initialCapacity, BinaryHeap.IndexKeeper indexKeeper, boolean isMinHeap)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Empties the queue.protected EdeleteElementAt(int index)EdeleteMin()Deletes the minimum element in the queue.EfindMin()Finds the minimum element in the queue.protected intgetCapacity()EgetElementAtIndex(int index)voidinsert(E element)Inserts an element into the queue.booleanisEmpty()Determines whether the queue is empty or not.protected voidpercolateDown(int index)protected voidpercolateUp(int index)protected voidpercolateUp(int index, E value)Heapify up the tree.protected voidsetElementAtIndex(int index, E value)intsize()Returns the size of the queue.java.lang.StringtoString()protected booleanvalidate()
-
-
-
Field Detail
-
DEFAULT_CAPACITY
protected static final int DEFAULT_CAPACITY
- See Also:
- Constant Field Values
-
heap
protected java.lang.Object[] heap
-
size
protected int size
-
indexKeeper
protected BinaryHeap.IndexKeeper indexKeeper
-
-
Constructor Detail
-
BinaryHeap
public BinaryHeap()
-
BinaryHeap
public BinaryHeap(boolean isMinHeap)
-
BinaryHeap
public BinaryHeap(int initialCapacity)
-
BinaryHeap
public BinaryHeap(int initialCapacity, boolean isMinHeap)
-
BinaryHeap
public BinaryHeap(int initialCapacity, BinaryHeap.IndexKeeper indexKeeper)
-
BinaryHeap
public BinaryHeap(int initialCapacity, BinaryHeap.IndexKeeper indexKeeper, boolean isMinHeap)
-
-
Method Detail
-
getCapacity
protected int getCapacity()
-
insert
public void insert(E element)
Description copied from interface:PriorityQueueInserts an element into the queue.- Specified by:
insertin interfacePriorityQueue<E extends java.lang.Comparable>
-
deleteMin
public E deleteMin()
Description copied from interface:PriorityQueueDeletes the minimum element in the queue.- Specified by:
deleteMinin interfacePriorityQueue<E extends java.lang.Comparable>- Returns:
- the minimum element in the queue. If the queue is empty, return null.
-
isEmpty
public boolean isEmpty()
Description copied from interface:PriorityQueueDetermines whether the queue is empty or not.- Specified by:
isEmptyin interfacePriorityQueue<E extends java.lang.Comparable>- Returns:
-
getElementAtIndex
public E getElementAtIndex(int index)
-
setElementAtIndex
protected void setElementAtIndex(int index, E value)
-
percolateUp
protected void percolateUp(int index)
-
percolateUp
protected void percolateUp(int index, E value)Heapify up the tree.- Parameters:
index- index to startvalue- value at the index
-
percolateDown
protected void percolateDown(int index)
-
clear
public void clear()
Description copied from interface:PriorityQueueEmpties the queue.- Specified by:
clearin interfacePriorityQueue<E extends java.lang.Comparable>
-
size
public int size()
Description copied from interface:PriorityQueueReturns the size of the queue.- Specified by:
sizein interfacePriorityQueue<E extends java.lang.Comparable>- Returns:
-
findMin
public E findMin()
Description copied from interface:PriorityQueueFinds the minimum element in the queue. This method is non-destructive peeking. The queue is left untouched.- Specified by:
findMinin interfacePriorityQueue<E extends java.lang.Comparable>- Returns:
- the minimum element in the queue. If the queue is empty, return null.
-
deleteElementAt
protected E deleteElementAt(int index)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
validate
protected boolean validate()
-
-