Package edu.uci.ics.jung.algorithms.util
Class MapBinaryHeap<T>
java.lang.Object
java.util.AbstractCollection<T>
edu.uci.ics.jung.algorithms.util.MapBinaryHeap<T>
- All Implemented Interfaces:
Iterable<T>,Collection<T>,Queue<T>
An array-based binary heap implementation of a priority queue,
which also provides
efficient
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.- Author:
- Joshua O'Madadhain
-
Constructor Summary
ConstructorsConstructorDescriptionCreates aMapBinaryHeapwhose heap ordering will be based on the natural ordering of the elements, which must beComparable.MapBinaryHeap(Collection<T> c) Creates aMapBinaryHeapbased on the specified collection whose heap ordering will be based on the natural ordering of the elements, which must beComparable.MapBinaryHeap(Collection<T> c, Comparator<T> comp) Creates aMapBinaryHeapbased on the specified collection whose heap ordering is based on the ordering of the elements specified byc.MapBinaryHeap(Comparator<T> comp) Creates aMapBinaryHeapwhose heap ordering is based on the ordering of the elements specified bycomp. -
Method Summary
Modifier and TypeMethodDescriptionbooleanInsertsointo this collection.voidclear()booleanelement()booleanisEmpty()Returnstrueif this collection contains no elements, andfalseotherwise.iterator()Returns anIteratorthat does not support modification of the heap.booleanpeek()Returns the element at the top of the heap; does not alter the heap.poll()remove()booleanThis data structure does not support the removal of arbitrary elements.booleanremoveAll(Collection<?> c) This data structure does not support the removal of arbitrary elements.booleanretainAll(Collection<?> c) This data structure does not support the removal of arbitrary elements.intsize()voidInforms 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).Methods inherited from class java.util.AbstractCollection
addAll, containsAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
addAll, containsAll, equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray, toArray, toArray
-
Constructor Details
-
MapBinaryHeap
Creates aMapBinaryHeapwhose heap ordering is based on the ordering of the elements specified bycomp.- Parameters:
comp- the comparator to use to order elements in the heap
-
MapBinaryHeap
public MapBinaryHeap()Creates aMapBinaryHeapwhose heap ordering will be based on the natural ordering of the elements, which must beComparable. -
MapBinaryHeap
Creates aMapBinaryHeapbased on the specified collection whose heap ordering will be based on the natural ordering of the elements, which must beComparable.- Parameters:
c- the collection ofComparableelements to add to the heap
-
MapBinaryHeap
Creates aMapBinaryHeapbased on the specified collection whose heap ordering is based on the ordering of the elements specified byc.- Parameters:
c- the collection of elements to add to the heapcomp- the comparator to use for items inc
-
-
Method Details
-
clear
public void clear()- Specified by:
clearin interfaceCollection<T>- Overrides:
clearin classAbstractCollection<T>- See Also:
-
add
Insertsointo this collection.- Specified by:
addin interfaceCollection<T>- Specified by:
addin interfaceQueue<T>- Overrides:
addin classAbstractCollection<T>
-
isEmpty
public boolean isEmpty()Returnstrueif this collection contains no elements, andfalseotherwise.- Specified by:
isEmptyin interfaceCollection<T>- Overrides:
isEmptyin classAbstractCollection<T>
-
peek
Returns the element at the top of the heap; does not alter the heap. -
size
public int size()- Specified by:
sizein interfaceCollection<T>- Specified by:
sizein classAbstractCollection<T>- Returns:
- the size of this heap
-
update
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).- Parameters:
o- the object whose key value has been updated
-
contains
- Specified by:
containsin interfaceCollection<T>- Overrides:
containsin classAbstractCollection<T>
-
iterator
Returns anIteratorthat does not support modification of the heap.- Specified by:
iteratorin interfaceCollection<T>- Specified by:
iteratorin interfaceIterable<T>- Specified by:
iteratorin classAbstractCollection<T>
-
remove
This data structure does not support the removal of arbitrary elements.- Specified by:
removein interfaceCollection<T>- Overrides:
removein classAbstractCollection<T>
-
removeAll
This data structure does not support the removal of arbitrary elements.- Specified by:
removeAllin interfaceCollection<T>- Overrides:
removeAllin classAbstractCollection<T>
-
retainAll
This data structure does not support the removal of arbitrary elements.- Specified by:
retainAllin interfaceCollection<T>- Overrides:
retainAllin classAbstractCollection<T>
-
element
- Specified by:
elementin interfaceQueue<T>- Throws:
NoSuchElementException
-
offer
-
poll
-
remove
-