public class DoubleLongMinHeap extends java.lang.Object implements DoubleLongHeap
Modifier and Type | Class and Description |
---|---|
private class |
DoubleLongMinHeap.UnsortedIter
Unsorted iterator - in heap order.
|
Modifier and Type | Field and Description |
---|---|
protected int |
size
Current size of heap.
|
private static int |
TWO_HEAP_INITIAL_SIZE
Initial size of the 2-ary heap.
|
protected double[] |
twoheap
Base heap.
|
protected long[] |
twovals
Base heap values.
|
Constructor and Description |
---|
DoubleLongMinHeap()
Constructor, with default size.
|
DoubleLongMinHeap(int minsize)
Constructor, with given minimum size.
|
Modifier and Type | Method and Description |
---|---|
void |
add(double o,
long v)
Add a key-value pair to the heap
|
void |
add(double key,
long val,
int max)
Add a key-value pair to the heap if it improves the top.
|
void |
clear()
Clear the heap contents.
|
boolean |
containsKey(double q)
Contains operation for a key (slow: with a linear scan).
|
boolean |
containsValue(long q)
Contains operation for a value (slow: with a linear scan).
|
private void |
heapifyDown(double cur,
long val)
Invoke heapify-down for the root object.
|
private void |
heapifyUp(int twopos,
double cur,
long val)
Heapify-Up method for 2-ary heap.
|
boolean |
isEmpty()
Is the heap empty?
|
double |
peekKey()
Get the current top key.
|
long |
peekValue()
Get the current top value.
|
void |
poll()
Remove the first element.
|
void |
replaceTopElement(double reinsert,
long val)
Combined operation that removes the top element, and inserts a new element instead.
|
int |
size()
Query the size.
|
java.lang.String |
toString() |
DoubleLongMinHeap.UnsortedIter |
unsortedIter()
Get an unsorted iterator to inspect the heap.
|
protected double[] twoheap
protected long[] twovals
protected int size
private static final int TWO_HEAP_INITIAL_SIZE
public DoubleLongMinHeap()
public DoubleLongMinHeap(int minsize)
minsize
- Minimum sizepublic void clear()
DoubleLongHeap
clear
in interface DoubleLongHeap
public int size()
DoubleLongHeap
size
in interface DoubleLongHeap
public boolean isEmpty()
DoubleLongHeap
isEmpty
in interface DoubleLongHeap
true
when the size is 0.public void add(double o, long v)
DoubleLongHeap
add
in interface DoubleLongHeap
o
- Keyv
- Valuepublic void add(double key, long val, int max)
DoubleLongHeap
add
in interface DoubleLongHeap
key
- Keyval
- Valuemax
- Desired maximum sizepublic void replaceTopElement(double reinsert, long val)
DoubleLongHeap
replaceTopElement
in interface DoubleLongHeap
reinsert
- Key of new elementval
- Value of new elementprivate void heapifyUp(int twopos, double cur, long val)
twopos
- Position in 2-ary heap.cur
- Current objectval
- Current valuepublic void poll()
DoubleLongHeap
poll
in interface DoubleLongHeap
private void heapifyDown(double cur, long val)
cur
- Object to insert.val
- Value to reinsert.public double peekKey()
DoubleLongHeap
peekKey
in interface DoubleLongHeap
public long peekValue()
DoubleLongHeap
peekValue
in interface DoubleLongHeap
public boolean containsKey(double q)
DoubleLongHeap
containsKey
in interface DoubleLongHeap
q
- Keytrue
if the key is contained in the heap.public boolean containsValue(long q)
DoubleLongHeap
containsValue
in interface DoubleLongHeap
q
- Valuetrue
if the value is contained in the heap.public java.lang.String toString()
toString
in class java.lang.Object
public DoubleLongMinHeap.UnsortedIter unsortedIter()
DoubleLongHeap
unsortedIter
in interface DoubleLongHeap
Copyright © 2019 ELKI Development Team. License information.