Class IntegerMinHeap
- java.lang.Object
-
- elki.utilities.datastructures.heap.IntegerMinHeap
-
- All Implemented Interfaces:
IntegerHeap
public class IntegerMinHeap extends java.lang.Object implements IntegerHeap
Binary heap for primitive types.This class is generated from a template.
- Since:
- 0.5.5
- Author:
- Erich Schubert
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
IntegerMinHeap.UnsortedIter
Unsorted iterator - in heap order.
-
Field Summary
Fields Modifier and Type Field Description protected int
size
Current size of heap.private static int
TWO_HEAP_INITIAL_SIZE
Initial size of the 2-ary heap.protected int[]
twoheap
Base heap.
-
Constructor Summary
Constructors Constructor Description IntegerMinHeap()
Constructor, with default size.IntegerMinHeap(int minsize)
Constructor, with given minimum size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int o)
Add a key-value pair to the heapvoid
add(int key, int max)
Add a key-value pair to the heap, except if the new element is larger than the top, and we are at design size (overflow)void
clear()
Delete all elements from the heap.private void
heapifyDown(int cur)
Invoke heapify-down for the root object.private void
heapifyUp(int twopos, int cur)
Heapify-Up method for 2-ary heap.boolean
isEmpty()
Is the heap empty?int
peek()
Get the current top keyint
poll()
Remove the first elementint
replaceTopElement(int reinsert)
Combined operation that removes the top element, and inserts a new element instead.int
size()
Query the sizejava.lang.String
toString()
IntegerMinHeap.UnsortedIter
unsortedIter()
Get an unsorted iterator to inspect the heap.
-
-
-
Field Detail
-
twoheap
protected int[] twoheap
Base heap.
-
size
protected int size
Current size of heap.
-
TWO_HEAP_INITIAL_SIZE
private static final int TWO_HEAP_INITIAL_SIZE
Initial size of the 2-ary heap.- See Also:
- Constant Field Values
-
-
Method Detail
-
clear
public void clear()
Description copied from interface:IntegerHeap
Delete all elements from the heap.- Specified by:
clear
in interfaceIntegerHeap
-
size
public int size()
Description copied from interface:IntegerHeap
Query the size- Specified by:
size
in interfaceIntegerHeap
- Returns:
- Size
-
isEmpty
public boolean isEmpty()
Description copied from interface:IntegerHeap
Is the heap empty?- Specified by:
isEmpty
in interfaceIntegerHeap
- Returns:
true
when the size is 0.
-
add
public void add(int o)
Description copied from interface:IntegerHeap
Add a key-value pair to the heap- Specified by:
add
in interfaceIntegerHeap
- Parameters:
o
- Key
-
add
public void add(int key, int max)
Description copied from interface:IntegerHeap
Add a key-value pair to the heap, except if the new element is larger than the top, and we are at design size (overflow)- Specified by:
add
in interfaceIntegerHeap
- Parameters:
key
- Keymax
- Maximum size of heap
-
replaceTopElement
public int replaceTopElement(int reinsert)
Description copied from interface:IntegerHeap
Combined operation that removes the top element, and inserts a new element instead.- Specified by:
replaceTopElement
in interfaceIntegerHeap
- Parameters:
reinsert
- New element to insert- Returns:
- Previous top element of the heap
-
heapifyUp
private void heapifyUp(int twopos, int cur)
Heapify-Up method for 2-ary heap.- Parameters:
twopos
- Position in 2-ary heap.cur
- Current object
-
poll
public int poll()
Description copied from interface:IntegerHeap
Remove the first element- Specified by:
poll
in interfaceIntegerHeap
- Returns:
- Top element
-
heapifyDown
private void heapifyDown(int cur)
Invoke heapify-down for the root object.- Parameters:
cur
- Object to insert.
-
peek
public int peek()
Description copied from interface:IntegerHeap
Get the current top key- Specified by:
peek
in interfaceIntegerHeap
- Returns:
- Top key
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
unsortedIter
public IntegerMinHeap.UnsortedIter unsortedIter()
Description copied from interface:IntegerHeap
Get an unsorted iterator to inspect the heap.- Specified by:
unsortedIter
in interfaceIntegerHeap
- Returns:
- Iterator
-
-