xxl.collections
Class DynamicHeap

java.lang.Object
  |
  +--xxl.collections.AbstractQueue
        |
        +--xxl.collections.Heap
              |
              +--xxl.collections.DynamicHeap

public class DynamicHeap
extends Heap

The DynamicHeap uses the ArrayResizer to increase or reduce the size of the array dynamically. This means that it is not necessary to know the maximum size of this heap in advance.

See Also:
ArrayResizer

Field Summary
static Function FACTORY_METHOD
          A factory method to create a new DynamicHeap.
protected  ArrayResizer resizer
          The ArrayResizer used for resize-operations of the array.
 
Fields inherited from class xxl.collections.Heap
array, comparator, FACTORY_METHOD, last
 
Fields inherited from class xxl.collections.AbstractQueue
FACTORY_METHOD
 
Constructor Summary
DynamicHeap()
          Creates a new DynamicHeap.
DynamicHeap(ArrayResizer resizer)
          Creates a new DynamicHeap.
DynamicHeap(java.util.Comparator comparator)
          Creates a new DynamicHeap.
DynamicHeap(java.util.Comparator comparator, ArrayResizer resizer)
          Creates a new DynamicHeap.
DynamicHeap(java.util.Iterator iterator)
           
DynamicHeap(java.util.Iterator iterator, java.util.Comparator comparator)
           
DynamicHeap(java.lang.Object[] array)
          Creates a new DynamicHeap.
DynamicHeap(java.lang.Object[] array, ArrayResizer resizer)
          Creates a new DynamicHeap.
DynamicHeap(java.lang.Object[] array, java.util.Comparator comparator)
          Creates a new DynamicHeap.
DynamicHeap(java.lang.Object[] array, java.util.Comparator comparator, ArrayResizer resizer)
          Creates a new DynamicHeap.
DynamicHeap(java.lang.Object[] array, int size)
          Creates a new DynamicHeap.
DynamicHeap(java.lang.Object[] array, int size, ArrayResizer resizer)
          Creates a new DynamicHeap.
DynamicHeap(java.lang.Object[] array, int size, java.util.Comparator comparator)
          Creates a new DynamicHeap.
DynamicHeap(java.lang.Object[] array, int size, java.util.Comparator comparator, ArrayResizer resizer)
          Creates a new DynamicHeap.
 
Method Summary
 void clear()
          Removes all elements from the heap.
 void insert(java.lang.Object object)
          Inserts an Object into the heap.
 void insertAll(java.util.Iterator objects)
          Inserts all elements of a given Iterator into the heap.
 java.lang.Object next()
          Returns the next element in the iteration.
 
Methods inherited from class xxl.collections.Heap
bubbleUp, heapify, peek, replace, sinkIn, size, supportsPeek
 
Methods inherited from class xxl.collections.AbstractQueue
close, hasNext, remove, replaceAll
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FACTORY_METHOD

public static final Function FACTORY_METHOD
A factory method to create a new DynamicHeap. It may be invoked with or without a given array. (see contract for FACTORY_METHOD in interface Queue)

resizer

protected ArrayResizer resizer
The ArrayResizer used for resize-operations of the array.
Constructor Detail

DynamicHeap

public DynamicHeap(java.lang.Object[] array,
                   int size,
                   java.util.Comparator comparator,
                   ArrayResizer resizer)
Creates a new DynamicHeap.
Parameters:
array - the array for which the heap is to be created
size - the size of the heap
comparator - the Comparator used to compare elements in the heap
resizer - the ArrayResizer used for resize-operations of the array

DynamicHeap

public DynamicHeap()
Creates a new DynamicHeap.

DynamicHeap

public DynamicHeap(java.util.Iterator iterator)

DynamicHeap

public DynamicHeap(ArrayResizer resizer)
Creates a new DynamicHeap.
Parameters:
resizer - the ArrayResizer used for resize-operations of the array

DynamicHeap

public DynamicHeap(java.util.Comparator comparator)
Creates a new DynamicHeap.
Parameters:
comparator - the Comparator used to compare elements in the heap

DynamicHeap

public DynamicHeap(java.util.Iterator iterator,
                   java.util.Comparator comparator)

DynamicHeap

public DynamicHeap(java.lang.Object[] array)
Creates a new DynamicHeap.
Parameters:
array - the array for which the heap is to be created

DynamicHeap

public DynamicHeap(java.util.Comparator comparator,
                   ArrayResizer resizer)
Creates a new DynamicHeap.
Parameters:
comparator - the Comparator used to compare elements in the heap
resizer - the ArrayResizer used for resize-operations of the array

DynamicHeap

public DynamicHeap(java.lang.Object[] array,
                   ArrayResizer resizer)
Creates a new DynamicHeap.
Parameters:
array - the array for which the heap is to be created
resizer - the ArrayResizer used for resize-operations of the array

DynamicHeap

public DynamicHeap(java.lang.Object[] array,
                   java.util.Comparator comparator)
Creates a new DynamicHeap.
Parameters:
array - the array for which the heap is to be created
comparator - the Comparator used to compare elements in the heap

DynamicHeap

public DynamicHeap(java.lang.Object[] array,
                   java.util.Comparator comparator,
                   ArrayResizer resizer)
Creates a new DynamicHeap.
Parameters:
array - the array for which the heap is to be created
comparator - the Comparator used to compare elements in the heap
resizer - the ArrayResizer used for resize-operations of the array

DynamicHeap

public DynamicHeap(java.lang.Object[] array,
                   int size)
Creates a new DynamicHeap.
Parameters:
array - the array for which the heap is to be created
size - the size of the heap

DynamicHeap

public DynamicHeap(java.lang.Object[] array,
                   int size,
                   ArrayResizer resizer)
Creates a new DynamicHeap.
Parameters:
array - the array for which the heap is to be created
size - the size of the heap
resizer - the ArrayResizer used for resize-operations of the array

DynamicHeap

public DynamicHeap(java.lang.Object[] array,
                   int size,
                   java.util.Comparator comparator)
Creates a new DynamicHeap.
Parameters:
array - the array for which the heap is to be created
size - the size of the heap
comparator - the Comparator used to compare elements in the heap
Method Detail

clear

public void clear()
Removes all elements from the heap.
Overrides:
clear in class Heap

insert

public void insert(java.lang.Object object)
Inserts an Object into the heap.
Overrides:
insert in class Heap

insertAll

public void insertAll(java.util.Iterator objects)
Inserts all elements of a given Iterator into the heap.
Parameters:
objects - an Iterator of Objects
Overrides:
insertAll in class Heap

next

public java.lang.Object next()
                      throws java.util.NoSuchElementException
Returns the next element in the iteration.
Returns:
the next element in the iteration.
Throws:
java.util.NoSuchElementException - iteration has no more elements.
Overrides:
next in class Heap