public class MapBinaryHeap<T>
extends java.util.AbstractCollection<T>
implements java.util.Queue<T>
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<T> 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<T> c,
java.util.Comparator<T> 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<T> 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(T o)
Inserts
o into this collection. |
void |
clear() |
boolean |
contains(java.lang.Object o) |
T |
element() |
boolean |
isEmpty()
Returns
true if this collection contains no elements, and
false otherwise. |
java.util.Iterator<T> |
iterator()
Returns an
Iterator that does not support modification
of the heap. |
boolean |
offer(T o) |
T |
peek()
Returns the element at the top of the heap; does not
alter the heap.
|
T |
poll() |
T |
pop()
|
T |
remove() |
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(T 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, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public MapBinaryHeap(java.util.Comparator<T> 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<T> 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 void clear()
public boolean add(T o)
o
into this collection.public boolean isEmpty()
true
if this collection contains no elements, and
false
otherwise.public T peek()
peek
in interface java.util.Queue<T>
@Deprecated public T pop() throws java.util.NoSuchElementException
java.util.NoSuchElementException
public int size()
public void update(T o)
o
- public boolean contains(java.lang.Object o)
public java.util.Iterator<T> iterator()
Iterator
that does not support modification
of the heap.public boolean remove(java.lang.Object o)
public boolean removeAll(java.util.Collection<?> c)
public boolean retainAll(java.util.Collection<?> c)
public T element() throws java.util.NoSuchElementException
element
in interface java.util.Queue<T>
java.util.NoSuchElementException
Copyright © 2021, 2022 Herve Girod. All Rights Reserved. Documentation and source under the BSD 3-Clause licence