|
||||||||||
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 Container
public boolean isEmpty()
Requires: True Ensures: isEmpty = (count = 0)
isEmpty
in interface Container
public boolean isFull()
Requires: True Ensures: isFull = (count = Capacity)
isFull
in interface Container
public int size()
Requires: True Ensures: result = size
size
in interface Container
public java.util.Enumeration<java.lang.Object> elements()
elements
in interface Container
java.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 Container
ContainerFullException
- when container already contains Capacity
elements.public void removeAll()
Requires: True Ensures: size = 0
removeAll
in interface Container
public java.lang.Object remove()
Requires: size >= 0 Ensures: size = old size - 1 old inorderSequence = obj ^ inorderSequence
remove
in interface Container
ContainerEmptyException
- when removing from an empty container.public java.lang.Object clone()
Requires: True Ensures: result = copy of heap
clone
in interface Container
clone
in class java.lang.Object
public java.lang.String toString()
Requires: true Ensures: result = string representation of tree
toString
in interface Container
toString
in class java.lang.Object
public 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 Container
equals
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |