org.neo4j.graphalgo.impl.util
Class FibonacciHeap<KeyType>

java.lang.Object
  extended by org.neo4j.graphalgo.impl.util.FibonacciHeap<KeyType>
Type Parameters:
KeyType - The datatype to be stored in this heap.

public class FibonacciHeap<KeyType>
extends Object

At least a partial implementation of a Fibonacci heap (a priority heap). Almost all code is based on the chapter about Fibonacci heaps in the book "Introduction to Algorithms" by Cormen, Leiserson, Rivest and Stein (second edition, 2001). Amortized times for almost all operations are O(1). extractMin() runs in amortized time O(log n), which then a delete() based upon it also would. This Fibonacci heap can store any datatype, given by the KeyType parameter, all it needs is a comparator for that type. To achieve the stated running times, it is needed that this comparator can do comparisons in constant time (usually the case).

Author:
Patrik Larsson

Nested Class Summary
 class FibonacciHeap.FibonacciHeapNode
          One entry in the fibonacci heap is stored as an instance of this class.
 
Constructor Summary
FibonacciHeap(Comparator<KeyType> keyComparator)
           
 
Method Summary
protected  void cascadingCut(FibonacciHeap.FibonacciHeapNode y)
          Internal helper function.
protected  void consolidate()
          Internal helper function.
protected  void cut(FibonacciHeap.FibonacciHeapNode x, FibonacciHeap.FibonacciHeapNode y)
          Internal helper function.
 void decreaseKey(FibonacciHeap.FibonacciHeapNode node, KeyType newKey)
          Raises the priority for an entry.
 KeyType extractMin()
          This removes and returns the entry with the highest priority.
 FibonacciHeap.FibonacciHeapNode getMinimum()
           
 FibonacciHeap.FibonacciHeapNode insert(KeyType key)
          Inserts a new value into the heap.
protected  void insertInRootList(FibonacciHeap.FibonacciHeapNode fNode)
          Internal helper function for moving nodes into the root list
 boolean isEmpty()
           
protected  void link(FibonacciHeap.FibonacciHeapNode y, FibonacciHeap.FibonacciHeapNode x)
          Internal helper function.
 int size()
           
 void union(FibonacciHeap<KeyType> other)
          Creates the union of two heaps by absorbing the other into this one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FibonacciHeap

public FibonacciHeap(Comparator<KeyType> keyComparator)
Method Detail

isEmpty

public boolean isEmpty()
Returns:
True if the heap is empty.

size

public int size()
Returns:
The number of entries in this heap.

getMinimum

public FibonacciHeap.FibonacciHeapNode getMinimum()
Returns:
The entry with the highest priority or null if the heap is empty.

insertInRootList

protected void insertInRootList(FibonacciHeap.FibonacciHeapNode fNode)
Internal helper function for moving nodes into the root list


insert

public FibonacciHeap.FibonacciHeapNode insert(KeyType key)
Inserts a new value into the heap.

Parameters:
key - the value to be inserted.
Returns:
The entry made into the heap.

union

public void union(FibonacciHeap<KeyType> other)
Creates the union of two heaps by absorbing the other into this one. Note: Destroys other


extractMin

public KeyType extractMin()
This removes and returns the entry with the highest priority.

Returns:
The value with the highest priority.

consolidate

protected void consolidate()
Internal helper function.


link

protected void link(FibonacciHeap.FibonacciHeapNode y,
                    FibonacciHeap.FibonacciHeapNode x)
Internal helper function. Makes root node y a child of root node x.


decreaseKey

public void decreaseKey(FibonacciHeap.FibonacciHeapNode node,
                        KeyType newKey)
Raises the priority for an entry.

Parameters:
node - The entry to recieve a higher priority.
newKey - The new value.

cut

protected void cut(FibonacciHeap.FibonacciHeapNode x,
                   FibonacciHeap.FibonacciHeapNode y)
Internal helper function. This removes y's child x and moves x to the root list.


cascadingCut

protected void cascadingCut(FibonacciHeap.FibonacciHeapNode y)
Internal helper function.



Copyright © 2002-2012 The Neo4j Graph Database Project. All Rights Reserved.