|
JUtil | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.cscott.jutil.AbstractHeap<K,V>
public abstract class AbstractHeap<K,V>
AbstractHeap
provides a skeletal implementation of
the Heap
interface, to minimize the effort required
to implement this interface.
Constructor Summary | |
---|---|
protected |
AbstractHeap(Comparator<K> c)
Sole constructor, for invocation by subclass constructors. |
Method Summary | |
---|---|
abstract void |
clear()
Removes all entries from this Heap . |
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(Map.Entry<K,V> me,
K newkey)
Replace the key in the specified map entry with the specified smaller key. |
abstract void |
delete(Map.Entry<K,V> me)
Remove the specified map entry from the mapping. |
abstract Collection<Map.Entry<K,V>> |
entries()
Returns a collection view of all the Map.Entry s
in this Heap . |
protected Comparator<Map.Entry<K,V>> |
entryComparator()
Returns a comparator which can be used to compare Map.Entry s. |
boolean |
equals(Object o)
Compares the specified object with this heap for equality. |
Map.Entry<K,V> |
extractMinimum()
Remove and return a map entry with minimal key. |
int |
hashCode()
Returns the hash code for this heap. |
abstract Map.Entry<K,V> |
insert(K key,
V value)
Inserts a node with the specified key and value into the Heap . |
protected void |
insert(Map.Entry<K,V> me)
This method should insert the specified Map.Entry ,
which is not currently in the Heap , into the
Heap . |
boolean |
isEmpty()
Returns true if this Heap has no more
entries. |
protected Comparator<K> |
keyComparator()
Returns the comparator used to compare keys in this Heap . |
abstract Map.Entry<K,V> |
minimum()
Returns a mapping entry with minimal key. |
protected K |
setKey(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 . |
String |
toString()
Returns a string representation of this Heap . |
void |
union(Heap<? extends K,? extends V> h)
Merges all of the mappings from the specified Heap
into this Heap . |
void |
updateKey(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. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected AbstractHeap(Comparator<K> c)
Method Detail |
---|
public abstract Map.Entry<K,V> insert(K key, V value)
Heap
Heap
. Returns the generated Map.Entry
which may be stored and eventually passed back to
decreaseKey()
or delete
to remove
this node.
insert
in interface Heap<K,V>
public abstract Map.Entry<K,V> minimum()
Heap
minimum
in interface Heap<K,V>
public abstract void decreaseKey(Map.Entry<K,V> me, K newkey)
Heap
decreaseKey
in interface Heap<K,V>
public abstract void delete(Map.Entry<K,V> me)
Heap
delete
in interface Heap<K,V>
public abstract int size()
Heap
Heap
.
size
in interface Heap<K,V>
public abstract Collection<Map.Entry<K,V>> entries()
Heap
Map.Entry
s
in this Heap
.
entries
in interface Heap<K,V>
public abstract void clear()
Heap
Heap
.
clear
in interface Heap<K,V>
public void updateKey(Map.Entry<K,V> me, K newkey)
Heap
updateKey
in interface Heap<K,V>
protected void insert(Map.Entry<K,V> me)
Map.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()
.
protected K setKey(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 Map.Entry<K,V> extractMinimum()
Heap
extractMinimum
in interface Heap<K,V>
public void union(Heap<? extends K,? extends V> h)
Heap
Heap
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.)
union
in interface Heap<K,V>
public boolean isEmpty()
Heap
true
if this Heap
has no more
entries.
isEmpty
in interface Heap<K,V>
public int hashCode()
Heap
Collection
returned by Heap.entries()
.
hashCode
in interface Heap<K,V>
hashCode
in class Object
public boolean equals(Object o)
Heap
true
iff the given object is also a
Heap
and the Collection
s returned
by their Heap.entries()
methods are equal using
the equals()
method of Collection
.
equals
in interface Heap<K,V>
equals
in class Object
public String toString()
Heap
Heap
.
toString
in interface Heap<K,V>
toString
in class Object
public Comparator<K> comparator()
Heap
,
or null
if the keys' natural ordering is used.
comparator
in interface Heap<K,V>
protected Comparator<K> keyComparator()
Heap
.
Will never return null
.
protected Comparator<Map.Entry<K,V>> entryComparator()
Map.Entry
s. Will never return null
.
|
JUtil | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |