Package net.cscott.jutil
Class AbstractHeap<K,V>
java.lang.Object
net.cscott.jutil.AbstractHeap<K,V>
- Direct Known Subclasses:
BinaryHeap,BinomialHeap,FibonacciHeap
AbstractHeap provides a skeletal implementation of
the Heap interface, to minimize the effort required
to implement this interface.- Author:
- C. Scott Ananian <cananian@alumni.princeton.edu>
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractHeap(Comparator<? super K> c) Sole constructor, for invocation by subclass constructors. -
Method Summary
Modifier and TypeMethodDescriptionabstract voidclear()Removes all entries from thisHeap.Comparator<? super K> Returns the comparator used to compare keys in thisHeap, ornullif the keys' natural ordering is used.abstract voiddecreaseKey(Map.Entry<K, V> me, K newkey) Replace the key in the specified map entry with the specified smaller key.abstract voidRemove the specified map entry from the mapping.abstract Collection<Map.Entry<K, V>> entries()protected Comparator<Map.Entry<K, V>> Returns a comparator which can be used to compareMap.Entrys.booleanCompares the specified object with this heap for equality.Remove and return a map entry with minimal key.inthashCode()Returns the hash code for this heap: one greater than the sum of the hash codes of its entries.protected voidInserts a node with the specified key and value into theHeap.booleanisEmpty()Returnstrueif thisHeaphas no more entries.protected Comparator<? super K> Returns the comparator used to compare keys in thisHeap.minimum()Returns a mapping entry with minimal key.protected KThis method should set the key for the specifiedMap.Entryto the givennewkey.abstract intsize()Returns the number of entries in thisHeap.toString()Returns a string representation of thisHeap.voidvoidReplace the key in the specified map entry with the specified key, which may be either larger or smaller than its current key.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
AbstractHeap
Sole constructor, for invocation by subclass constructors.
-
-
Method Details
-
insert
Description copied from interface:Heap -
minimum
Description copied from interface:HeapReturns a mapping entry with minimal key. -
decreaseKey
Description copied from interface:HeapReplace the key in the specified map entry with the specified smaller key.- Specified by:
decreaseKeyin interfaceHeap<K,V>
-
delete
Description copied from interface:HeapRemove the specified map entry from the mapping. -
size
public abstract int size()Description copied from interface:HeapReturns the number of entries in thisHeap. -
entries
Description copied from interface:Heap -
clear
public abstract void clear()Description copied from interface:HeapRemoves all entries from thisHeap. -
updateKey
Description copied from interface:HeapReplace the key in the specified map entry with the specified key, which may be either larger or smaller than its current key. -
insert
-
setKey
This 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(). -
extractMinimum
Description copied from interface:HeapRemove and return a map entry with minimal key.- Specified by:
extractMinimumin interfaceHeap<K,V>
-
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.) -
isEmpty
public boolean isEmpty()Description copied from interface:HeapReturnstrueif thisHeaphas no more entries. -
hashCode
public int hashCode()Description copied from interface:HeapReturns the hash code for this heap: one greater than the sum of the hash codes of its entries. -
equals
Description copied from interface:HeapCompares the specified object with this heap for equality. Returnstrueiff the given object is also aHeapwith the same entries, in any order: each key-value pair is in both heaps the same number of times. The heaps' comparators are not compared. -
toString
Description copied from interface:HeapReturns a string representation of thisHeap. -
comparator
Returns the comparator used to compare keys in thisHeap, ornullif the keys' natural ordering is used.- Specified by:
comparatorin interfaceHeap<K,V>
-
keyComparator
Returns the comparator used to compare keys in thisHeap. Will never returnnull. -
entryComparator
Returns a comparator which can be used to compareMap.Entrys. Will never returnnull.
-