![]() |
Template Class
|
#include "boost/f_heap.hpp" template <class T> class boost::fibonacci_heap_base { public: class iterator { public: iterator(); bool operator== (iterator const& it) const; bool operator!= (iterator const& it) const; T const& operator* () const; T const* operator-> () const; iterator &operator++ (); iterator operator++ (int); }; public: bool empty() const; size_type size() const; iterator begin() const; iterator end() const; private: fibonacci_heap_base(fibonacci_heap_base const&); // deliberately not implemented void operator=(fibonacci_heap_base const&); // deliberately not implemented }; template <class T, class Comp = std::less<T> > class boost::fibonacci_heap: public boost::fibonacci_heap_base<T> { public: typedef unsigned integral type size_type; typedef pointer type pointer; typedef T value_type; typedef T const& const_reference; typedef typename fibonacci_heap_base<T>::iterator const_iterator; typedef Comp compare_type; explicit fibonacci_heap(Comp const& comp = Comp()); pointer push(T const& val); void pop(); T const& top() const; void remove(pointer ptr); template <typename K> void change_top(K const& val); template <typename K> void change(pointer ptr, K const& val); template <typename K> void decrease(pointer ptr, K const& val); template <typename K> void increase(pointer ptr, K const& val); }; |
Fibonacci heaps are organized as a collection of trees which are somewhat
similar to Binomial trees. Here is what is basically done: If a node becomes
a root (this happens eg. if new node is pushed on the heap or during certain
heap operations) it is checked if there is already a root with the same
degree. If this is the case, the two nodes are linked to combine a new
tree by making the smaller node a child of the larger node. Thereby a
tree with a larger degree is formed which is potentially linked again
with a corresponding tree. Thus, the degrees of the roots of all trees
differs. If a node has to be removed from its parent, eg. because it
became larger due to a
The similarity to Binomial trees is due to their construction: In a Binomial tree, each tree of degree n has n children with degrees 0 to n-1. This also applies to the trees in Fibonacci heaps since they are basically constructed the same way as Binomial trees are constructed, namely by using two trees of degree n to form a tree of degree n+1. However, due to the cuts applies in Fibonacci heaps the trees in a Fibonacci heap are normally not Binomial heaps.
For more information on Fibonacci heaps see eg. Introduction to Algorithms, Corman, Leiserson, Rivest, MIT Press, or Network Flow, Ahuja, Magnanti, Orlin, Prentice Hall. I used the latter to create this implementation (I like their descriptions in general because they often map quite directly to an implementation). However, the implementation looks quite different from this description to get the implementation fast...
For a description of the methods of See Also
heap(3),
heap-common(3)