|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractQueue<E>
de.lmu.ifi.dbs.elki.utilities.datastructures.heap.Heap<E>
E - Element type. Should be Comparable or a
Comparator needs to be given.public class Heap<E>

Basic in-memory heap structure. Closely related to a PriorityQueue,
but here we can override methods to obtain e.g. a TopBoundedHeap
| Nested Class Summary | |
|---|---|
protected class |
Heap.Itr
Iterator over queue elements. |
| Field Summary | |
|---|---|
private Comparator<? super E> |
comparator
The comparator or null |
private static int |
DEFAULT_INITIAL_CAPACITY
Default initial capacity |
int |
modCount
(Structural) modification counter. |
private Object[] |
queue
Heap storage Note: keep private; all write access should be done through putInQueue(int, java.lang.Object) for subclasses to track! |
private static long |
serialVersionUID
Serial version |
protected int |
size
Current number of objects |
| Constructor Summary | |
|---|---|
Heap()
Default constructor: default capacity, natural ordering. |
|
Heap(Comparator<? super E> comparator)
Constructor with Comparator. |
|
Heap(int size)
Constructor with initial capacity, natural ordering. |
|
Heap(int size,
Comparator<? super E> comparator)
Constructor with initial capacity and Comparator. |
|
| Method Summary | |
|---|---|
protected E |
castQueueElement(int n)
|
void |
clear()
|
protected int |
compare(int pos1,
int pos2)
|
protected int |
compareExternal(E o1,
int pos2)
|
protected int |
compareExternalExternal(E o1,
E o2)
|
private void |
considerResize(int requiredSize)
Test whether we need to resize to have the requested capacity. |
boolean |
contains(Object o)
|
private void |
grow(int newsize)
Execute the actual resize operation. |
protected void |
heapifyDown(int pos)
Execute a "Heapify Downwards" aka "SiftDown". |
protected void |
heapifyUp(int pos)
Execute a "Heapify Upwards" aka "SiftUp". |
protected void |
heapifyUpParent(int pos)
Start a heapify up at the parent of this node, since we've changed a child |
Iterator<E> |
iterator()
|
private int |
leftChild(int pos)
Compute left child index in heap array. |
boolean |
offer(E e)
|
private int |
parent(int pos)
Compute parent index in heap array. |
E |
peek()
|
E |
poll()
|
protected void |
putInQueue(int index,
Object e)
Put an element into the queue at a given position. |
protected E |
removeAt(int pos)
Remove the element at the given position. |
private int |
rightChild(int pos)
Compute right child index in heap array. |
int |
size()
|
protected void |
swap(int a,
int b)
Swap two elements in the heap. |
ArrayList<E> |
toSortedArrayList()
Return the heap as a sorted array list, by repeated polling. |
| Methods inherited from class java.util.AbstractQueue |
|---|
add, addAll, element, remove |
| Methods inherited from class java.util.AbstractCollection |
|---|
containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Collection |
|---|
containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, toArray, toArray |
| Field Detail |
|---|
private static final long serialVersionUID
private Object[] queue
putInQueue(int, java.lang.Object) for subclasses to track!
protected int size
private final Comparator<? super E> comparator
null
public transient int modCount
private static final int DEFAULT_INITIAL_CAPACITY
| Constructor Detail |
|---|
public Heap()
public Heap(int size)
size - initial sizepublic Heap(Comparator<? super E> comparator)
Comparator.
comparator - Comparator
public Heap(int size,
Comparator<? super E> comparator)
Comparator.
size - initial capacitycomparator - Comparator| Method Detail |
|---|
public boolean offer(E e)
offer in interface Queue<E>public E peek()
peek in interface Queue<E>public E poll()
poll in interface Queue<E>protected E removeAt(int pos)
pos - Element position.private int parent(int pos)
pos - Element index
private int leftChild(int pos)
pos - Element index
private int rightChild(int pos)
pos - Element index
protected void heapifyUp(int pos)
pos - insertion positionprotected void heapifyUpParent(int pos)
pos - Position to start the modification.protected void heapifyDown(int pos)
pos - re-insertion position
protected void putInQueue(int index,
Object e)
index - Indexe - Element
protected void swap(int a,
int b)
a - Elementb - Element
protected int compare(int pos1,
int pos2)
protected int compareExternal(E o1,
int pos2)
protected int compareExternalExternal(E o1,
E o2)
protected E castQueueElement(int n)
public int size()
size in interface Collection<E>size in class AbstractCollection<E>private void considerResize(int requiredSize)
requiredSize - required capacityprivate void grow(int newsize)
newsize - New sizepublic void clear()
clear in interface Collection<E>clear in class AbstractQueue<E>public boolean contains(Object o)
contains in interface Collection<E>contains in class AbstractCollection<E>public Iterator<E> iterator()
iterator in interface Iterable<E>iterator in interface Collection<E>iterator in class AbstractCollection<E>public ArrayList<E> toSortedArrayList()
|
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||