FibHeap< _Prio, _ItemIntMap, _Compare > Class Template Reference
[Auxiliary Data Structures]


Detailed Description

template<typename _Prio, typename _ItemIntMap, typename _Compare>
class lemon::FibHeap< _Prio, _ItemIntMap, _Compare >

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. Compare 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:
_Prio Type of the priority of the items.
_ItemIntMap A read and writable Item int map, used internally to handle the cross references.
_Compare A class for the ordering of the priorities. The default is std::less<_Prio>.
See also:
BinHeap

Dijkstra

Author:
Jacint Szabo
#include <lemon/fib_heap.h>

List of all members.

Public Types

enum  State { IN_HEAP = 0, PRE_HEAP = -1, POST_HEAP = -2 }
 Status of the nodes. More...

Public Member Functions

 FibHeap (ItemIntMap &_iimap)
 The constructor.
 FibHeap (ItemIntMap &_iimap, 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 Prio & prio () const
 Returns the minimum priority relative to Compare.
const Prio & operator[] (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

Enumerator:
IN_HEAP  The node is in the heap.
PRE_HEAP  The node has never been in the heap.
POST_HEAP  The node was in the heap but it got out of it.


Constructor & Destructor Documentation

FibHeap ( ItemIntMap &  _iimap  )  [inline, explicit]

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

FibHeap ( ItemIntMap &  _iimap,
const Compare &  _comp 
) [inline]

_iimap 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:
i The item.
st The state. It should not be IN_HEAP.


Generated on Thu Jun 4 04:04:07 2009 for LEMON by  doxygen 1.5.9