choco.cp.solver.constraints.global.geost.dataStructures
Class HeapDescending

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<Heapable>
              extended by choco.cp.solver.constraints.global.geost.dataStructures.HeapDescending
All Implemented Interfaces:
HeapImpl, Serializable, Cloneable, Iterable<Heapable>, Collection<Heapable>, List<Heapable>, RandomAccess

public final class HeapDescending
extends ArrayList<Heapable>
implements HeapImpl

An implementation of a priority queue according to Cormen, Leiserson and Rivest. Sorts in descending order.

Version:
1.0 2/23/96
Author:
Michael J. Radwin
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
HeapDescending()
          Constructs a heap with no elements.
HeapDescending(Heapable[] anArray)
          Constructs the heap in O(N) time, using a technique similar to bottom-up construction.
 
Method Summary
protected  void exchange(int i, int j)
          Exchanges the elements stored at the two locations
 Heapable extractMax()
          Removes the maximum (top) element from the Heap, decreases the size of the heap by one, and returns the maximum element.
 Heapable getMax()
          Returns the maximum (top) element from the Heap
protected  void heapify(int i)
          Also known as downheap, restores the heap condition starting at node i and working its way down.
 void insert(Heapable key)
          Inserts key into the heap, and then upheaps that key to a position where the heap property is satisfied.
protected  int left(int i)
          Returns the Vector index of the left child
protected  int parent(int i)
          Returns the Vector index of the parent
 Heapable remove()
          Removes an element from the heap.
 void removeAllElements()
           
protected  int right(int i)
          Returns the Vector index of the right child
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface choco.cp.solver.constraints.global.geost.dataStructures.HeapImpl
isEmpty, size
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

HeapDescending

public HeapDescending(Heapable[] anArray)
Constructs the heap in O(N) time, using a technique similar to bottom-up construction.


HeapDescending

public HeapDescending()
Constructs a heap with no elements.

Method Detail

left

protected int left(int i)
Returns the Vector index of the left child


right

protected int right(int i)
Returns the Vector index of the right child


parent

protected int parent(int i)
Returns the Vector index of the parent


exchange

protected void exchange(int i,
                        int j)
Exchanges the elements stored at the two locations


heapify

protected void heapify(int i)
Also known as downheap, restores the heap condition starting at node i and working its way down.


extractMax

public Heapable extractMax()
                    throws NoSuchElementException
Removes the maximum (top) element from the Heap, decreases the size of the heap by one, and returns the maximum element.

Throws:
NoSuchElementException

getMax

public Heapable getMax()
                throws NoSuchElementException
Returns the maximum (top) element from the Heap

Throws:
NoSuchElementException

remove

public Heapable remove()
                throws NoSuchElementException
Removes an element from the heap.

Specified by:
remove in interface HeapImpl
Throws:
NoSuchElementException

insert

public void insert(Heapable key)
Inserts key into the heap, and then upheaps that key to a position where the heap property is satisfied.

Specified by:
insert in interface HeapImpl

removeAllElements

public void removeAllElements()
Specified by:
removeAllElements in interface HeapImpl


Copyright © 2012. All Rights Reserved.