public class BinomialHeap<K,V> extends AbstractHeap<K,V> implements java.lang.Cloneable
BinomialHeap allows
O(lg n) time bounds for insert, minimum, extract-min, union,
decrease-key, and delete operations. Implementation is based on
the description in Introduction to Algorithms by Cormen,
Leiserson, and Rivest, on page 400 and following.| Constructor and Description |
|---|
BinomialHeap()
Constructs a new, empty
BinomialHeap, sorted according
to the keys' natural order. |
BinomialHeap(java.util.Collection<? extends java.util.Map.Entry<? extends K,? extends V>> collection,
java.util.Comparator<K> comparator)
Constructs a binomial heap from a collection of
Map.Entrys and a key comparator. |
BinomialHeap(java.util.Comparator<K> c)
Constructs a new, empty
BinomialHeap, sorted according
to the given comparator. |
BinomialHeap(Heap<K,? extends V> h)
Constructs a new binomial heap with the same entries as the specified
Heap. |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all mappings from this map.
|
BinomialHeap<K,V> |
clone()
Creates a new BinomialHeap with all the key-value pairs this one
has.
|
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()
Return an unmodifiable collection of entries in this heap.
|
java.util.Map.Entry<K,V> |
extractMinimum()
Remove and return the map entry with minimal key.
|
java.util.Map.Entry<K,V> |
find(K key)
Lookup a
Map.Entry in the heap with key equal to
the specified key. |
java.util.Map.Entry<K,V> |
insert(K key,
V value)
Associates the specified value with the specified key in the map.
|
protected void |
insert(java.util.Map.Entry<K,V> me)
|
boolean |
isEmpty()
Returns
true if this map contains no key-value mappings. |
static void |
main(java.lang.String[] argv)
Self-test function.
|
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 size of this map.
|
void |
union(BinomialHeap<K,V> m)
Merges all of the mappings from the specified map to this
map.
|
void |
union(Heap<? extends K,? extends V> h)
Add all the entries from the given heap to this one.
|
comparator, entryComparator, equals, hashCode, keyComparator, toString, updateKeypublic BinomialHeap()
BinomialHeap, sorted according
to the keys' natural order. All keys inserted into the new map
must implement the Comparable interface. O(1) time.public BinomialHeap(java.util.Comparator<K> c)
BinomialHeap, sorted according
to the given comparator. O(1) time.public BinomialHeap(Heap<K,? extends V> h)
Heap. O(n) time.public java.util.Map.Entry<K,V> minimum()
public void union(Heap<? extends K,? extends V> h)
BinomialHeap
and its entry comparator is the same as this one's.
Otherwise, it takes O(n) time.public void union(BinomialHeap<K,V> m)
this. After calling union(), the
specified map will be empty.public java.util.Map.Entry<K,V> insert(K key, V value)
insert(). O(lg 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> extractMinimum()
extractMinimum in interface Heap<K,V>extractMinimum in class AbstractHeap<K,V>public void decreaseKey(java.util.Map.Entry<K,V> me, K newkey)
decreaseKey in interface Heap<K,V>decreaseKey in class AbstractHeap<K,V>public void delete(java.util.Map.Entry<K,V> me)
public java.util.Collection<java.util.Map.Entry<K,V>> entries()
public int size()
public void clear()
public boolean isEmpty()
true if this map contains no key-value mappings.public BinomialHeap<K,V> clone()
clone in class java.lang.Objectpublic java.util.Map.Entry<K,V> find(K key)
Map.Entry in the heap with key equal to
the specified key. O(n), although pruning is done on subtrees
with root larger than the specified key. What this means is
that the smaller the key is, the faster this will run.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[] argv)
Copyright (c) 2006 C. Scott Ananian