
public class DoubleLongMaxHeap extends Object implements DoubleLongHeap
| Modifier and Type | Class and Description | 
|---|---|
private class  | 
DoubleLongMaxHeap.UnsortedIter
Unsorted iterator - in heap order. 
 | 
| Modifier and Type | Field and Description | 
|---|---|
private static int | 
FOUR_HEAP_INITIAL_SIZE
Initial size of 4-ary heap when initialized.
 
 21 = 4-ary heap of height 2: 1 + 4 + 4*4
 
 85 = 4-ary heap of height 3: 21 + 4*4*4
 
 341 = 4-ary heap of height 4: 85 + 4*4*4*4
 
 Since we last grew by 255 (to 511), let's use 341. 
 | 
protected double[] | 
fourheap
Extension heap. 
 | 
protected long[] | 
fourvals
Extension heapvalues. 
 | 
protected int | 
modCount
(Structural) modification counter. 
 | 
protected int | 
size
Current size of heap. 
 | 
private static int | 
TWO_HEAP_INITIAL_SIZE
Initial size of the 2-ary heap. 
 | 
private static int | 
TWO_HEAP_MAX_SIZE
Maximum size of the 2-ary heap. 
 | 
protected double[] | 
twoheap
Base heap. 
 | 
protected long[] | 
twovals
Base heap values. 
 | 
| Constructor and Description | 
|---|
DoubleLongMaxHeap()
Constructor, with default size. 
 | 
DoubleLongMaxHeap(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. 
 | 
private void | 
heapifyDown(double reinsert,
           long val)
Invoke heapify-down for the root object. 
 | 
private void | 
heapifyDown2(int twopos,
            double cur,
            long val)
Heapify-Down for 2-ary heap. 
 | 
private void | 
heapifyDown4(int fourpos,
            double cur,
            long val)
Heapify-Down for 4-ary heap. 
 | 
private void | 
heapifyUp2(int twopos,
          double cur,
          long val)
Heapify-Up method for 2-ary heap. 
 | 
private void | 
heapifyUp4(int fourpos,
          double cur,
          long val)
Heapify-Up method for 4-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 
 | 
String | 
toString()  | 
DoubleLongMaxHeap.UnsortedIter | 
unsortedIter()
Get an unsorted iterator to inspect the heap. 
 | 
protected double[] twoheap
protected long[] twovals
protected double[] fourheap
protected long[] fourvals
protected int size
protected int modCount
private static final int TWO_HEAP_MAX_SIZE
private static final int TWO_HEAP_INITIAL_SIZE
private static final int FOUR_HEAP_INITIAL_SIZE
public DoubleLongMaxHeap()
public DoubleLongMaxHeap(int minsize)
minsize - Minimum sizepublic void clear()
DoubleLongHeapclear in interface DoubleLongHeappublic int size()
DoubleLongHeapsize in interface DoubleLongHeappublic boolean isEmpty()
DoubleLongHeapisEmpty in interface DoubleLongHeaptrue when the size is 0.public void add(double o,
       long v)
DoubleLongHeapadd in interface DoubleLongHeapo - Keyv - Valuepublic void add(double key,
       long val,
       int max)
DoubleLongHeapadd in interface DoubleLongHeapkey - Keyval - Valuemax - Desired maximum sizepublic void replaceTopElement(double reinsert,
                     long val)
DoubleLongHeapreplaceTopElement in interface DoubleLongHeapreinsert - Key of new elementval - Value of new elementprivate void heapifyUp2(int twopos,
              double cur,
              long val)
twopos - Position in 2-ary heap.cur - Current objectval - Current valueprivate void heapifyUp4(int fourpos,
              double cur,
              long val)
fourpos - Position in 4-ary heap.cur - Current objectval - Current valuepublic void poll()
DoubleLongHeappoll in interface DoubleLongHeapprivate void heapifyDown(double reinsert,
               long val)
reinsert - Object to insert.val - Value to reinsert.private void heapifyDown2(int twopos,
                double cur,
                long val)
twopos - Position in 2-ary heap.cur - Current objectval - Value to reinsert.private void heapifyDown4(int fourpos,
                double cur,
                long val)
fourpos - Position in 4-ary heap.cur - Current objectval - Value to reinsert.public double peekKey()
DoubleLongHeappeekKey in interface DoubleLongHeappublic long peekValue()
DoubleLongHeappeekValue in interface DoubleLongHeappublic DoubleLongMaxHeap.UnsortedIter unsortedIter()
DoubleLongHeapunsortedIter in interface DoubleLongHeap