|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--harpoon.Util.Collections.AbstractHeap | +--harpoon.Util.Collections.FibonacciHeap
A 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 Summary | |
FibonacciHeap()
Creates a new, empty FibonacciHeap , sorted according
to its keys' natural order. |
|
FibonacciHeap(Collection collection,
Comparator comparator)
Constructs a new heap from a collection of Map.Entry s and a key comparator. |
|
FibonacciHeap(Comparator c)
Creates a new, empty FibonacciHeap , sorted according
to the given Comparator . |
|
FibonacciHeap(Heap h)
Constructs a new heap with the same entries as the specified Heap . |
Method Summary | |
void |
clear()
Removes all entries from this Heap . |
void |
decreaseKey(Map.Entry me,
Object newkey)
Replace the key in the specified map entry with the specified smaller key. |
void |
delete(Map.Entry me)
Remove the specified map entry from the mapping. |
Collection |
entries()
Returns a collection view of all the Map.Entry s
in this Heap . |
Map.Entry |
extractMinimum()
Remove and return a map entry with minimal key. |
protected void |
insert(Map.Entry me)
This method should insert the specified Map.Entry ,
which is not currently in the Heap , into the
Heap . |
Map.Entry |
insert(Object key,
Object value)
Insert an entry into the heap. |
static void |
main(String[] args)
Self-test method. |
Map.Entry |
minimum()
Returns a mapping entry with minimal key. |
protected Object |
setKey(Map.Entry me,
Object 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 h)
|
void |
union(Heap h)
Merges all of the mappings from the specified Heap
into this Heap . |
Methods inherited from class harpoon.Util.Collections.AbstractHeap |
comparator, entryComparator, equals, hashCode, isEmpty, keyComparator, toString, updateKey |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public 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(Comparator c)
FibonacciHeap
, sorted according
to the given Comparator
. O(1) time.
public FibonacciHeap(Heap h)
Heap
. O(n) time.
public FibonacciHeap(Collection collection, Comparator comparator)
Map.Entry
s and a key comparator. O(n) time.
Method Detail |
public Map.Entry insert(Object key, Object value)
insert
in interface Heap
insert
in class AbstractHeap
protected void insert(Map.Entry me)
AbstractHeap
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()
.
insert
in class AbstractHeap
public Map.Entry minimum()
Heap
minimum
in interface Heap
minimum
in class AbstractHeap
public void union(FibonacciHeap h)
public void union(Heap 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
union
in class AbstractHeap
public Map.Entry extractMinimum()
Heap
extractMinimum
in interface Heap
extractMinimum
in class AbstractHeap
public void decreaseKey(Map.Entry me, Object newkey)
Heap
decreaseKey
in interface Heap
decreaseKey
in class AbstractHeap
public void delete(Map.Entry me)
Heap
delete
in interface Heap
delete
in class AbstractHeap
public int size()
Heap
Heap
.
size
in interface Heap
size
in class AbstractHeap
public void clear()
Heap
Heap
.
clear
in interface Heap
clear
in class AbstractHeap
public Collection entries()
Heap
Map.Entry
s
in this Heap
.
entries
in interface Heap
entries
in class AbstractHeap
protected final Object setKey(Map.Entry me, Object newkey)
AbstractHeap
Map.Entry
to the given newkey
.
Implementation is optional, but it is required if you use the
default implementation of updateKey()
.
setKey
in class AbstractHeap
public static void main(String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |