public abstract class AbstractHeap<K,V> extends java.lang.Object implements Heap<K,V>
AbstractHeap provides a skeletal implementation of
the Heap interface, to minimize the effort required
to implement this interface.| Modifier | Constructor and Description |
|---|---|
protected |
AbstractHeap(java.util.Comparator<K> c)
Sole constructor, for invocation by subclass constructors.
|
| Modifier and Type | Method and Description |
|---|---|
abstract void |
clear()
Removes all entries from this
Heap. |
java.util.Comparator<K> |
comparator()
Returns the comparator used to compare keys in this
Heap,
or null if the keys' natural ordering is used. |
abstract void |
decreaseKey(java.util.Map.Entry<K,V> me,
K newkey)
Replace the key in the specified map entry with the specified
smaller key.
|
abstract void |
delete(java.util.Map.Entry<K,V> me)
Remove the specified map entry from the mapping.
|
abstract java.util.Collection<java.util.Map.Entry<K,V>> |
entries()
Returns a collection view of all the
Map.Entrys
in this Heap. |
protected java.util.Comparator<java.util.Map.Entry<K,V>> |
entryComparator()
Returns a comparator which can be used to compare
Map.Entrys. |
boolean |
equals(java.lang.Object o)
Compares the specified object with this heap for equality.
|
java.util.Map.Entry<K,V> |
extractMinimum()
Remove and return a map entry with minimal key.
|
int |
hashCode()
Returns the hash code for this heap.
|
abstract java.util.Map.Entry<K,V> |
insert(K key,
V value)
Inserts a node with the specified key and value into the
Heap. |
protected void |
insert(java.util.Map.Entry<K,V> me)
|
boolean |
isEmpty()
Returns
true if this Heap has no more
entries. |
protected java.util.Comparator<K> |
keyComparator()
Returns the comparator used to compare keys in this
Heap. |
abstract 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. |
abstract int |
size()
Returns the number of entries in this
Heap. |
java.lang.String |
toString()
Returns a string representation of this
Heap. |
void |
union(Heap<? extends K,? extends V> h)
|
void |
updateKey(java.util.Map.Entry<K,V> me,
K newkey)
Replace the key in the specified map entry with the specified key,
which may be either larger or smaller than its current key.
|
protected AbstractHeap(java.util.Comparator<K> c)
public abstract java.util.Map.Entry<K,V> insert(K key, V value)
HeapHeap. Returns the generated Map.Entry
which may be stored and eventually passed back to
decreaseKey() or delete to remove
this node.public abstract java.util.Map.Entry<K,V> minimum()
Heappublic abstract void decreaseKey(java.util.Map.Entry<K,V> me, K newkey)
HeapdecreaseKey in interface Heap<K,V>public abstract void delete(java.util.Map.Entry<K,V> me)
Heappublic abstract int size()
HeapHeap.public abstract java.util.Collection<java.util.Map.Entry<K,V>> entries()
HeapMap.Entrys
in this Heap.public abstract void clear()
HeapHeap.public void updateKey(java.util.Map.Entry<K,V> me, K newkey)
Heapprotected K setKey(java.util.Map.Entry<K,V> me, K newkey)
Map.Entry to the given newkey.
Implementation is optional, but it is required if you use the
default implementation of updateKey().public java.util.Map.Entry<K,V> extractMinimum()
HeapextractMinimum in interface Heap<K,V>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 boolean isEmpty()
Heaptrue if this Heap has no more
entries.public int hashCode()
HeapCollection returned by Heap.entries().public boolean equals(java.lang.Object o)
Heaptrue iff the given object is also a
Heap and the Collections returned
by their Heap.entries() methods are equal using
the equals() method of Collection.public java.lang.String toString()
HeapHeap.public java.util.Comparator<K> comparator()
Heap,
or null if the keys' natural ordering is used.comparator in interface Heap<K,V>protected java.util.Comparator<K> keyComparator()
Heap.
Will never return null.Copyright (c) 2006 C. Scott Ananian