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

java.lang.Object
  extended by choco.cp.solver.constraints.global.geost.dataStructures.Heap

public final class Heap
extends Object

A priority queue according to Cormen, Leiserson and Rivest.

The heap can be constructed in O(N) time by copying an array, or O(N log N) time by staring with an empty heap and performing N insertions.

Version:
1.0 2/23/96
Author:
Michael J. Radwin

Constructor Summary
Heap()
          Constructs a heap with keys sorted in descending order.
Heap(boolean descending)
          Constructs a heap with the given sorting order.
Heap(Heapable[] anArray)
          Constructs the heap by copying an unordered array.
Heap(Heapable[] anArray, boolean descending)
          Constructs the heap by copying an unordered array.
 
Method Summary
 void clear()
          Removes all keys from the heap.
 void insert(Heapable key)
          Inserts a key into the heap.
 boolean isEmpty()
          Returns true if there are no keys in the heap, false otherwise.
 Heapable remove()
          Removes the top key from the heap.
 int size()
          Returns the number of keys in the heap.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Heap

public Heap(Heapable[] anArray,
            boolean descending)
Constructs the heap by copying an unordered array. Sorts keys in descending order if descending is true, ascending order otherwise. Takes O(N) time.


Heap

public Heap(Heapable[] anArray)
Constructs the heap by copying an unordered array. Sorts keys in descending order. Takes O(N) time.


Heap

public Heap(boolean descending)
Constructs a heap with the given sorting order. Takes O(N) time.

Parameters:
descending - true if keys should be sorted in descending order.

Heap

public Heap()
Constructs a heap with keys sorted in descending order. Takes O(N) time.

Method Detail

isEmpty

public boolean isEmpty()
Returns true if there are no keys in the heap, false otherwise. Takes O(1) time.


size

public int size()
Returns the number of keys in the heap. Takes O(1) time.


clear

public void clear()
Removes all keys from the heap. Takes O(N) time.


remove

public Heapable remove()
                throws NoSuchElementException
Removes the top key from the heap. Takes O(N log N) time.

Throws:
NoSuchElementException

insert

public void insert(Heapable key)
Inserts a key into the heap. Takes O(N log N) time.



Copyright © 2012. All Rights Reserved.