Package oracle.spatial.network.lod
Class IdentifiableBinaryHeap<E extends Identifiable & java.lang.Comparable>
- java.lang.Object
-
- oracle.spatial.network.lod.IdentifiableBinaryHeap<E>
-
- All Implemented Interfaces:
BinaryHeap.IndexKeeper<E>
,IdentifiablePriorityQueue<E>
,PriorityQueue<E>
public class IdentifiableBinaryHeap<E extends Identifiable & java.lang.Comparable> extends java.lang.Object implements IdentifiablePriorityQueue<E>, BinaryHeap.IndexKeeper<E>
a binary Min. heap priority queue implementation Note the elements have to implement the Identifiable and Comparable interface (int compareTo(Object obj) )
-
-
Constructor Summary
Constructors Constructor Description IdentifiableBinaryHeap()
IdentifiableBinaryHeap(int initialCapacity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Empties the queue.E
deleteElementAt(int index)
E
deleteMin()
Deletes the minimum element in the queue.int
findElementIndex(E element)
E
findMin()
Finds the minimum element in the queue.E
getElement(long id)
Returns the element with the input ID, if the element exists; otherwise, returns null.void
insert(E element)
Inserts an element into the queue.boolean
isEmpty()
Determines whether the queue is empty or not.E
replaceElement(long id, E newElement)
Replace the old element of the specified id with a new element.void
setIndex(E element, int index)
int
size()
Returns the size of the queue.java.lang.String
toString()
-
-
-
Method Detail
-
clear
public void clear()
Description copied from interface:PriorityQueue
Empties the queue.- Specified by:
clear
in interfacePriorityQueue<E extends Identifiable & java.lang.Comparable>
-
getElement
public E getElement(long id)
Description copied from interface:IdentifiablePriorityQueue
Returns the element with the input ID, if the element exists; otherwise, returns null.- Specified by:
getElement
in interfaceIdentifiablePriorityQueue<E extends Identifiable & java.lang.Comparable>
- Parameters:
id
- ID of the element- Returns:
-
insert
public void insert(E element)
Description copied from interface:PriorityQueue
Inserts an element into the queue.- Specified by:
insert
in interfacePriorityQueue<E extends Identifiable & java.lang.Comparable>
-
replaceElement
public E replaceElement(long id, E newElement)
Description copied from interface:IdentifiablePriorityQueue
Replace the old element of the specified id with a new element. The ID of the new element does not need to be the same as the old element. If the old element does not exist in the queue, then simply insert the new element into the queue.- Specified by:
replaceElement
in interfaceIdentifiablePriorityQueue<E extends Identifiable & java.lang.Comparable>
- Parameters:
id
- ID of the old elementnewElement
- new element- Returns:
-
findElementIndex
public int findElementIndex(E element)
-
deleteElementAt
public E deleteElementAt(int index)
-
size
public int size()
Description copied from interface:PriorityQueue
Returns the size of the queue.- Specified by:
size
in interfacePriorityQueue<E extends Identifiable & java.lang.Comparable>
- Returns:
-
isEmpty
public boolean isEmpty()
Description copied from interface:PriorityQueue
Determines whether the queue is empty or not.- Specified by:
isEmpty
in interfacePriorityQueue<E extends Identifiable & 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 Identifiable & java.lang.Comparable>
- Returns:
- the minimum element in the queue. If the queue is empty, return null.
-
deleteMin
public E deleteMin()
Description copied from interface:PriorityQueue
Deletes the minimum element in the queue.- Specified by:
deleteMin
in interfacePriorityQueue<E extends Identifiable & java.lang.Comparable>
- Returns:
- the minimum element in the queue. If the queue is empty, return null.
-
setIndex
public void setIndex(E element, int index)
- Specified by:
setIndex
in interfaceBinaryHeap.IndexKeeper<E extends Identifiable & java.lang.Comparable>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-