|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectFlexOr.container.Heap
public class Heap
| Constructor Summary | |
|---|---|
Heap(int capacity,
BinaryPredicate orderComparison,
BinaryPredicate equalComparison)
Define an empty heap. |
|
Heap(java.lang.Object[] array,
int capacity,
BinaryPredicate orderComparison,
BinaryPredicate equalComparison)
Define a heap from a given array of Objects. |
|
| Method Summary | |
|---|---|
void |
add(java.lang.Object obj)
Adds obj to the heap. |
int |
capacity()
Maximum number of elements that can be stored in the heap. |
java.lang.Object |
clone()
Return a copy of the heap that points to the same objects as in the original heap. |
boolean |
contains(java.lang.Object obj)
Determines whether an element is in the tree. |
java.util.Enumeration<java.lang.Object> |
elements()
Returns an enumerator sequentially scanning the heap. |
boolean |
equals(java.lang.Object container)
Check for equality of contents of two containers. |
boolean |
isEmpty()
Check if the container is empty. |
boolean |
isFull()
Check if the container is full. |
java.lang.Object |
remove()
Remove the top element in the heap. |
void |
removeAll()
Empty the container. |
int |
size()
Returns the number of elements in the container. |
java.lang.String |
toString()
Return a string representation of the contents of the heap. |
| Methods inherited from class java.lang.Object |
|---|
getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Heap(int capacity,
BinaryPredicate orderComparison,
BinaryPredicate equalComparison)
capacity - Create heap space of the specified capacity.orderComparison - defines how nodes are compared when
deciding which branch to take.equalComparison - defines how nodes
are checked for equality.
TooSmallException - when caller requests a Capacity < 2
Class invariant:
heap[1..currentSize] has the heap property. (forall i: 1..currentSize :: heap[i] orderComparison heap[2*i] and heap[i] orderComparison heap[2*i+1] )
public Heap(java.lang.Object[] array,
int capacity,
BinaryPredicate orderComparison,
BinaryPredicate equalComparison)
array - Create a heap from these objects.capacity - Create heap space of capacity max(capacity, array.length).orderComparison - defines how nodes are compared when
deciding which branch to take.equalComparison - defines how nodes
are checked for equality.
TooSmallException - when caller requests a size < 2.| Method Detail |
|---|
public boolean contains(java.lang.Object obj)
Requires: True Ensures: contains(obj) => result = true   not contains(obj) => result = false
contains in interface Containerpublic boolean isEmpty()
Requires: True Ensures: isEmpty = (count = 0)
isEmpty in interface Containerpublic boolean isFull()
Requires: True Ensures: isFull = (count = Capacity)
isFull in interface Containerpublic int size()
Requires: True Ensures: result = size
size in interface Containerpublic java.util.Enumeration<java.lang.Object> elements()
elements in interface Containerjava.util.NoSuchElementException - when nextElement is called with an empty
enumeration sequence.public int capacity()
public void add(java.lang.Object obj)
obj to the heap.
Requires: size < Capacity Ensures: contains(obj) = true size = old size + 1
add in interface ContainerContainerFullException - when container already contains Capacity
elements.public void removeAll()
Requires: True Ensures: size = 0
removeAll in interface Containerpublic java.lang.Object remove()
Requires: size >= 0 Ensures: size = old size - 1 old inorderSequence = obj ^ inorderSequence
remove in interface ContainerContainerEmptyException - when removing from an empty container.public java.lang.Object clone()
Requires: True Ensures: result = copy of heap
clone in interface Containerclone in class java.lang.Objectpublic java.lang.String toString()
Requires: true Ensures: result = string representation of tree
toString in interface ContainertoString in class java.lang.Objectpublic boolean equals(java.lang.Object container)
Requires: True Ensures: result = true => container contents are equal result = false => container contents are not equal
equals in interface Containerequals in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||