public class FibonacciHeap<K,V> extends AbstractHeap<K,V>
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.
| Constructor and Description |
|---|
FibonacciHeap()
Creates a new, empty
FibonacciHeap, sorted according
to its keys' natural order. |
FibonacciHeap(java.util.Collection<? extends java.util.Map.Entry<? extends K,? extends V>> collection,
java.util.Comparator<K> comparator)
Constructs a new heap from a collection of
Map.Entrys and a key comparator. |
FibonacciHeap(java.util.Comparator<K> c)
Creates a new, empty
FibonacciHeap, sorted according
to the given Comparator. |
FibonacciHeap(Heap<K,? extends V> h)
Constructs a new heap with the same entries as the specified
Heap. |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all entries from this
Heap. |
void |
decreaseKey(java.util.Map.Entry<K,V> me,
K newkey)
Replace the key in the specified map entry with the specified
smaller key.
|
void |
delete(java.util.Map.Entry<K,V> me)
Remove the specified map entry from the mapping.
|
java.util.Collection<java.util.Map.Entry<K,V>> |
entries()
Returns a collection view of all the
Map.Entrys
in this Heap. |
java.util.Map.Entry<K,V> |
extractMinimum()
Remove and return a map entry with minimal key.
|
java.util.Map.Entry<K,V> |
insert(K key,
V value)
Insert an entry into the heap.
|
protected void |
insert(java.util.Map.Entry<K,V> me)
|
static void |
main(java.lang.String[] args)
Self-test method.
|
java.util.Map.Entry<K,V> |
minimum()
Returns a mapping entry with minimal key.
|
protected K |
setKey(java.util.Map.Entry<K,V> me,
K newkey)
This method should set the key for the specified
Map.Entry to the given newkey. |
int |
size()
Returns the number of entries in this
Heap. |
void |
union(FibonacciHeap<K,V> h) |
void |
union(Heap<? extends K,? extends V> h)
|
comparator, entryComparator, equals, hashCode, isEmpty, keyComparator, toString, updateKeypublic FibonacciHeap()
FibonacciHeap, sorted according
to its keys' natural order. All keys inserted into the new
map must implement the Comparable interface.
O(1) time.public FibonacciHeap(java.util.Comparator<K> c)
FibonacciHeap, sorted according
to the given Comparator. O(1) time.public FibonacciHeap(Heap<K,? extends V> h)
Heap. O(n) time.protected void insert(java.util.Map.Entry<K,V> me)
AbstractHeapMap.Entry,
which is not currently in the Heap, into the
Heap. Implementation is optional, but it is required
if you use the default implementation of updateKey().insert in class AbstractHeap<K,V>public java.util.Map.Entry<K,V> minimum()
Heappublic void union(FibonacciHeap<K,V> h)
public void union(Heap<? extends K,? extends V> h)
HeapHeap
into this Heap. Note that duplicates are
permitted. After calling union(), the Heap
passed in as an argument will be empty.
Note that usually efficient implementations of this method require
that the Heap argument be from the same implementation
as this. (That is, they must both be binomial heaps, or
both fibonacci heaps, etc.)
public java.util.Map.Entry<K,V> extractMinimum()
HeapextractMinimum in interface Heap<K,V>extractMinimum in class AbstractHeap<K,V>public void decreaseKey(java.util.Map.Entry<K,V> me, K newkey)
HeapdecreaseKey in interface Heap<K,V>decreaseKey in class AbstractHeap<K,V>public void delete(java.util.Map.Entry<K,V> me)
Heappublic int size()
HeapHeap.public void clear()
HeapHeap.public java.util.Collection<java.util.Map.Entry<K,V>> entries()
HeapMap.Entrys
in this Heap.protected final K setKey(java.util.Map.Entry<K,V> me, K newkey)
AbstractHeapMap.Entry to the given newkey.
Implementation is optional, but it is required if you use the
default implementation of updateKey().setKey in class AbstractHeap<K,V>public static void main(java.lang.String[] args)
Copyright (c) 2006 C. Scott Ananian