Package net.cscott.jutil
Class FibonacciHeap<K,V>
java.lang.Object
net.cscott.jutil.AbstractHeap<K,V>
net.cscott.jutil.FibonacciHeap<K,V>
A
FibonacciHeap allows amortized O(1) time bounds for
create, insert, minimum, union, and decrease-key operations, and
amortized O(lg n) run times for extract-min and delete.
Implementation is based on the description in Introduction to Algorithms by Cormen, Leiserson, and Riverst, in Chapter 21.
- Author:
- C. Scott Ananian <cananian@alumni.princeton.edu>
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new, emptyFibonacciHeap, sorted according to its keys' natural order.FibonacciHeap(Collection<? extends Map.Entry<? extends K, ? extends V>> collection, Comparator<? super K> comparator) Constructs a new heap from a collection ofMap.Entrys and a key comparator.FibonacciHeap(Comparator<? super K> c) Creates a new, emptyFibonacciHeap, sorted according to the givenComparator.FibonacciHeap(Heap<K, ? extends V> h) Constructs a new heap with the same entries as the specifiedHeap. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all entries from thisHeap.voiddecreaseKey(Map.Entry<K, V> me, K newkey) Replace the key in the specified map entry with the specified smaller key.voidRemove the specified map entry from the mapping.entries()Remove and return a map entry with minimal key.protected voidInsert an entry into the heap.minimum()Returns a mapping entry with minimal key.protected final KThis method should set the key for the specifiedMap.Entryto the givennewkey.intsize()Returns the number of entries in thisHeap.voidunion(FibonacciHeap<K, V> h) voidMethods inherited from class net.cscott.jutil.AbstractHeap
comparator, entryComparator, equals, hashCode, isEmpty, keyComparator, toString, updateKeyMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
FibonacciHeap
public FibonacciHeap()Creates a new, emptyFibonacciHeap, sorted according to its keys' natural order. All keys inserted into the new map must implement theComparableinterface. O(1) time. -
FibonacciHeap
Creates a new, emptyFibonacciHeap, sorted according to the givenComparator. O(1) time. -
FibonacciHeap
Constructs a new heap with the same entries as the specifiedHeap. O(n) time. -
FibonacciHeap
public FibonacciHeap(Collection<? extends Map.Entry<? extends K, ? extends V>> collection, Comparator<? super K> comparator) Constructs a new heap from a collection ofMap.Entrys and a key comparator. O(n) time.
-
-
Method Details
-
insert
Insert an entry into the heap. -
insert
Description copied from class:AbstractHeapThis method should insert the specifiedMap.Entry, which is not currently in theHeap, into theHeap. Implementation is optional, but it is required if you use the default implementation ofupdateKey().- Overrides:
insertin classAbstractHeap<K,V>
-
minimum
Description copied from interface:HeapReturns a mapping entry with minimal key. -
union
-
union
Description copied from interface:HeapMerges all of the mappings from the specifiedHeapinto thisHeap. Note that duplicates are permitted. After callingunion(), theHeappassed in as an argument will be empty.Note that usually efficient implementations of this method require that the
Heapargument be from the same implementation asthis. (That is, they must both be binomial heaps, or both fibonacci heaps, etc.) -
extractMinimum
Description copied from interface:HeapRemove and return a map entry with minimal key.- Specified by:
extractMinimumin interfaceHeap<K,V> - Overrides:
extractMinimumin classAbstractHeap<K,V>
-
decreaseKey
Description copied from interface:HeapReplace the key in the specified map entry with the specified smaller key.- Specified by:
decreaseKeyin interfaceHeap<K,V> - Specified by:
decreaseKeyin classAbstractHeap<K,V>
-
delete
Description copied from interface:HeapRemove the specified map entry from the mapping. -
size
public int size()Description copied from interface:HeapReturns the number of entries in thisHeap. -
clear
public void clear()Description copied from interface:HeapRemoves all entries from thisHeap. -
entries
Description copied from interface:Heap -
setKey
Description copied from class:AbstractHeapThis method should set the key for the specifiedMap.Entryto the givennewkey. Implementation is optional, but it is required if you use the default implementation ofupdateKey().- Overrides:
setKeyin classAbstractHeap<K,V>
-