Class JGraphFibonacciHeap
java.lang.Object
com.jgraph.algebra.JGraphFibonacciHeap
This class implements a priority queue.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classImplements a node of the Fibonacci heap. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected JGraphFibonacciHeap.Nodeprotected MapMaps from elements to nodesprotected int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidPerforms a cascading cut operation.protected voidConsolidates the trees in the heap by joining trees of equal degree until there are no more trees of equal degree in the root list.protected voidThe reverse of the link operation: removes x from the child list of y.voiddecreaseKey(JGraphFibonacciHeap.Node x, double k) Decreases the key value for a heap node, given the new value to take on.voidDeletes a node from the heap given the reference to the node.Returns the node that represents element.voidinsert(JGraphFibonacciHeap.Node node, double key) Inserts a new data element into the heap.booleanisEmpty()protected voidMake node y a child of node x.min()Returns the smallest element in the heap.Removes the smallest element from the heap.intsize()Returns the size of the heap which is measured in the number of elements contained in the heap.static JGraphFibonacciHeapJoins two Fibonacci heaps into a new one.
-
Field Details
-
nodes
Maps from elements to nodes -
min
-
size
protected int size
-
-
Constructor Details
-
JGraphFibonacciHeap
public JGraphFibonacciHeap()
-
-
Method Details
-
getNode
Returns the node that represents element. -
isEmpty
public boolean isEmpty() -
decreaseKey
Decreases the key value for a heap node, given the new value to take on. The structure of the heap may be changed and will not be consolidated.Running time: O(1) amortized
- Parameters:
x- node to decrease the key ofk- new key value for node x- Throws:
IllegalArgumentException- Thrown if k is larger than x.key value.
-
delete
Deletes a node from the heap given the reference to the node. The trees in the heap will be consolidated, if necessary. This operation may fail to remove the correct element if there are nodes with key value -Infinity.Running time: O(log n) amortized
- Parameters:
x- node to remove from heap
-
insert
Inserts a new data element into the heap. No heap consolidation is performed at this time, the new node is simply inserted into the root list of this heap.Running time: O(1) actual
- Parameters:
node- new node to insert into heapkey- key value associated with data object
-
min
Returns the smallest element in the heap. This smallest element is the one with the minimum key value.Running time: O(1) actual
- Returns:
- heap node with the smallest key
-
removeMin
Removes the smallest element from the heap. This will cause the trees in the heap to be consolidated, if necessary. Does not remove the data node so that the current key remains stored.Running time: O(log n) amortized
- Returns:
- node with the smallest key
-
size
public int size()Returns the size of the heap which is measured in the number of elements contained in the heap.Running time: O(1) actual
- Returns:
- number of elements in the heap
-
union
Joins two Fibonacci heaps into a new one. No heap consolidation is performed at this time. The two root lists are simply joined together.Running time: O(1) actual
- Parameters:
h1- first heaph2- second heap- Returns:
- new heap containing h1 and h2
-
cascadingCut
Performs a cascading cut operation. This cuts y from its parent and then does the same for its parent, and so on up the tree.Running time: O(log n); O(1) excluding the recursion
- Parameters:
y- node to perform cascading cut on
-
consolidate
protected void consolidate()Consolidates the trees in the heap by joining trees of equal degree until there are no more trees of equal degree in the root list.Running time: O(log n) amortized
-
cut
The reverse of the link operation: removes x from the child list of y. This method assumes that min is non-null.Running time: O(1)
- Parameters:
x- child of y to be removed from y's child listy- parent of x about to lose a child
-
link
Make node y a child of node x.Running time: O(1) actual
- Parameters:
y- node to become childx- node to become parent
-