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 interface
BinaryHeap.IndexKeeper<E>
-
Field Summary
Fields Modifier and Type Field Description protected static int
DEFAULT_CAPACITY
protected java.lang.Object[]
heap
protected BinaryHeap.IndexKeeper
indexKeeper
protected int
size
-
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 void
clear()
Empties the queue.protected E
deleteElementAt(int index)
E
deleteMin()
Deletes the minimum element in the queue.E
findMin()
Finds the minimum element in the queue.protected int
getCapacity()
E
getElementAtIndex(int index)
void
insert(E element)
Inserts an element into the queue.boolean
isEmpty()
Determines whether the queue is empty or not.protected void
percolateDown(int index)
protected void
percolateUp(int index)
protected void
percolateUp(int index, E value)
Heapify up the tree.protected void
setElementAtIndex(int index, E value)
int
size()
Returns the size of the queue.java.lang.String
toString()
protected boolean
validate()
-
-
-
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:PriorityQueue
Inserts an element into the queue.- Specified by:
insert
in interfacePriorityQueue<E extends java.lang.Comparable>
-
deleteMin
public E deleteMin()
Description copied from interface:PriorityQueue
Deletes the minimum element in the queue.- Specified by:
deleteMin
in 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:PriorityQueue
Determines whether the queue is empty or not.- Specified by:
isEmpty
in 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:PriorityQueue
Empties the queue.- Specified by:
clear
in interfacePriorityQueue<E extends java.lang.Comparable>
-
size
public int size()
Description copied from interface:PriorityQueue
Returns the size of the queue.- Specified by:
size
in interfacePriorityQueue<E extends java.lang.Comparable>
- Returns:
-
findMin
public E findMin()
Description copied from interface:PriorityQueue
Finds the minimum element in the queue. This method is non-destructive peeking. The queue is left untouched.- Specified by:
findMin
in 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:
toString
in classjava.lang.Object
-
validate
protected boolean validate()
-
-