All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
List of all members | Public Types | Public Member Functions
FibHeap< PRIO, IM, CMP > Class Template Reference

Detailed Description

template<typename PRIO, typename IM, typename CMP>
class lemon::FibHeap< PRIO, IM, CMP >

This class implements the Fibonacci heap data structure. A heap is a data structure for storing items with specified values called priorities in such a way that finding the item with minimum priority is efficient. CMP specifies the ordering of the priorities. In a heap one can change the priority of an item, add or erase an item, etc.

The methods increase and erase are not efficient in a Fibonacci heap. In case of many calls to these operations, it is better to use a binary heap.

Parameters
PRIOType of the priority of the items.
IMA read and writable Item int map, used internally to handle the cross references.
CMPA class for the ordering of the priorities. The default is std::less<PRIO>.
See Also
BinHeap
Dijkstra

#include <lemon/fib_heap.h>

Public Types

enum  State { IN_HEAP = 0, PRE_HEAP = -1, POST_HEAP = -2 }
 Type to represent the items states. More...
 
typedef IM ItemIntMap
 
 
typedef PRIO Prio
 
 
typedef ItemIntMap::Key Item
 
 
typedef std::pair< Item, PrioPair
 
 
typedef CMP Compare
 
 

Public Member Functions

 FibHeap (ItemIntMap &map)
 The constructor.
 
 FibHeap (ItemIntMap &map, const Compare &comp)
 The constructor.
 
int size () const
 The number of items stored in the heap.
 
bool empty () const
 Checks if the heap stores no items.
 
void clear ()
 Make empty this heap.
 
void set (const Item &item, const Prio &value)
 item gets to the heap with priority value independently if item was already there.
 
void push (const Item &item, const Prio &value)
 Adds item to the heap with priority value.
 
Item top () const
 Returns the item with minimum priority relative to Compare.
 
const Prioprio () const
 Returns the minimum priority relative to Compare.
 
const Priooperator[] (const Item &item) const
 Returns the priority of item.
 
void pop ()
 Deletes the item with minimum priority relative to Compare.
 
void erase (const Item &item)
 Deletes item from the heap.
 
void decrease (Item item, const Prio &value)
 Decreases the priority of item to value.
 
void increase (Item item, const Prio &value)
 Increases the priority of item to value.
 
State state (const Item &item) const
 Returns if item is in, has already been in, or has never been in the heap.
 
void state (const Item &i, State st)
 Sets the state of the item in the heap.
 

Member Enumeration Documentation

enum State

Each Item element have a state associated to it. It may be "in heap", "pre heap" or "post heap". The latter two are indifferent from the heap's point of view, but may be useful to the user.

The item-int map must be initialized in such way that it assigns PRE_HEAP (-1) to any element to be put in the heap.

Enumerator:
IN_HEAP 

= 0.

PRE_HEAP 

= -1.

POST_HEAP 

= -2.

Constructor & Destructor Documentation

FibHeap ( ItemIntMap map)
inlineexplicit

map should be given to the constructor, since it is used internally to handle the cross references.

FibHeap ( ItemIntMap map,
const Compare comp 
)
inline

map should be given to the constructor, since it is used internally to handle the cross references. comp is an object for ordering of the priorities.

Member Function Documentation

int size ( ) const
inline

Returns the number of items stored in the heap.

bool empty ( ) const
inline

Returns true if and only if the heap stores no items.

void clear ( )
inline

Make empty this heap. It does not change the cross reference map. If you want to reuse a heap what is not surely empty you should first clear the heap and after that you should set the cross reference map for each item to PRE_HEAP.

void set ( const Item item,
const Prio value 
)
inline

This method calls push(item, value) if item is not stored in the heap and it calls decrease(item, value) or increase(item, value) otherwise.

void push ( const Item item,
const Prio value 
)
inline

Adds item to the heap with priority value.

Precondition
item must not be stored in the heap.
Item top ( ) const
inline

This method returns the item with minimum priority relative to Compare.

Precondition
The heap must be nonempty.
const Prio& prio ( ) const
inline

It returns the minimum priority relative to Compare.

Precondition
The heap must be nonempty.
const Prio& operator[] ( const Item item) const
inline

It returns the priority of item.

Precondition
item must be in the heap.
void pop ( )
inline

This method deletes the item with minimum priority relative to Compare from the heap.

Precondition
The heap must be non-empty.
void erase ( const Item item)
inline

This method deletes item from the heap, if item was already stored in the heap. It is quite inefficient in Fibonacci heaps.

void decrease ( Item  item,
const Prio value 
)
inline

This method decreases the priority of item to value.

Precondition
item must be stored in the heap with priority at least value relative to Compare.
void increase ( Item  item,
const Prio value 
)
inline

This method sets the priority of item to value. Though there is no precondition on the priority of item, this method should be used only if it is indeed necessary to increase (relative to Compare) the priority of item, because this method is inefficient.

State state ( const Item item) const
inline

This method returns PRE_HEAP if item has never been in the heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP otherwise. In the latter case it is possible that item will get back to the heap again.

void state ( const Item i,
State  st 
)
inline

Sets the state of the item in the heap. It can be used to manually clear the heap when it is important to achive the better time _complexity.

Parameters
iThe item.
stThe state. It should not be IN_HEAP.