public class MapBinaryHeap
extends java.util.AbstractCollection
implements java.util.Collection
update() and contains operations.
It contains extra infrastructure (a hash table) to keep track of the
position of each element in the array; thus, if the key value of an element
changes, it may be "resubmitted" to the heap via update
so that the heap can reposition it efficiently, as necessary.| Constructor and Description |
|---|
MapBinaryHeap()
Creates a
MapBinaryHeap whose heap ordering
will be based on the natural ordering of the elements,
which must be Comparable. |
MapBinaryHeap(java.util.Collection c)
Creates a
MapBinaryHeap based on the specified
collection whose heap ordering
will be based on the natural ordering of the elements,
which must be Comparable. |
MapBinaryHeap(java.util.Collection c,
java.util.Comparator comp)
Creates a
MapBinaryHeap based on the specified collection
whose heap ordering
is based on the ordering of the elements specified by c. |
MapBinaryHeap(java.util.Comparator comp)
Creates a
MapBinaryHeap whose heap ordering
is based on the ordering of the elements specified by c. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(java.lang.Object o)
Inserts
o into this collection. |
void |
clear() |
boolean |
contains(java.lang.Object o) |
boolean |
isEmpty()
Returns
true if this collection contains no elements, and
false otherwise. |
java.util.Iterator |
iterator()
Returns an
Iterator that does not support modification
of the heap. |
java.lang.Object |
peek()
Returns the element at the top of the heap; does not
alter the heap.
|
java.lang.Object |
pop()
Removes the element at the top of this heap, and returns it.
|
boolean |
remove(java.lang.Object o)
This data structure does not support the removal of arbitrary elements.
|
boolean |
removeAll(java.util.Collection c)
This data structure does not support the removal of arbitrary elements.
|
boolean |
retainAll(java.util.Collection c)
This data structure does not support the removal of arbitrary elements.
|
int |
size()
Returns the size of this heap.
|
void |
update(java.lang.Object o)
Informs the heap that this object's internal key value has been
updated, and that its place in the heap may need to be shifted
(up or down).
|
addAll, containsAll, toArray, toArray, toStringpublic MapBinaryHeap(java.util.Comparator comp)
MapBinaryHeap whose heap ordering
is based on the ordering of the elements specified by c.public MapBinaryHeap()
MapBinaryHeap whose heap ordering
will be based on the natural ordering of the elements,
which must be Comparable.public MapBinaryHeap(java.util.Collection c)
MapBinaryHeap based on the specified
collection whose heap ordering
will be based on the natural ordering of the elements,
which must be Comparable.public MapBinaryHeap(java.util.Collection c,
java.util.Comparator comp)
MapBinaryHeap based on the specified collection
whose heap ordering
is based on the ordering of the elements specified by c.public void clear()
clear in interface java.util.Collectionclear in class java.util.AbstractCollectionCollection.clear()public boolean add(java.lang.Object o)
o into this collection.add in interface java.util.Collectionadd in class java.util.AbstractCollectionpublic boolean isEmpty()
true if this collection contains no elements, and
false otherwise.isEmpty in interface java.util.CollectionisEmpty in class java.util.AbstractCollectionpublic java.lang.Object peek()
throws java.util.NoSuchElementException
java.util.NoSuchElementExceptionpublic java.lang.Object pop()
throws java.util.NoSuchElementException
java.util.NoSuchElementExceptionpublic int size()
size in interface java.util.Collectionsize in class java.util.AbstractCollectionpublic void update(java.lang.Object o)
o - public boolean contains(java.lang.Object o)
contains in interface java.util.Collectioncontains in class java.util.AbstractCollectionCollection.contains(java.lang.Object)public java.util.Iterator iterator()
Iterator that does not support modification
of the heap.iterator in interface java.lang.Iterableiterator in interface java.util.Collectioniterator in class java.util.AbstractCollectionpublic boolean remove(java.lang.Object o)
remove in interface java.util.Collectionremove in class java.util.AbstractCollectionpublic boolean removeAll(java.util.Collection c)
removeAll in interface java.util.CollectionremoveAll in class java.util.AbstractCollectionpublic boolean retainAll(java.util.Collection c)
retainAll in interface java.util.CollectionretainAll in class java.util.AbstractCollection