Heap< Priority, ItemIntMap > Class Template Reference
[Concepts]


Detailed Description

template<typename Priority, typename ItemIntMap>
class lemon::concepts::Heap< Priority, ItemIntMap >

Concept class describing the main interface of heaps. #include <lemon/concepts/heap.h>

List of all members.

Public Types

enum  State
 Type to represent the states of the items. More...
typedef ItemIntMap::Key Item
 Type of the items stored in the heap.
typedef Priority Prio
 Type of the priorities.

Public Member Functions

 Heap (ItemIntMap &map)
 The constructor.
int size () const
 The number of items stored in the heap.
bool empty () const
 Checks if the heap is empty.
void clear ()
 Makes the heap empty.
void push (const Item &i, const Prio &p)
 Inserts an item into the heap with the given priority.
Item top () const
 Returns the item having minimum priority.
Prio prio () const
 The minimum priority.
void pop ()
 Removes the item having minimum priority.
void erase (const Item &i)
 Removes an item from the heap.
Prio operator[] (const Item &i) const
 The priority of an item.
void set (const Item &i, const Prio &p)
 Sets the priority of an item or inserts it, if it is not stored in the heap.
void decrease (const Item &i, const Prio &p)
 Decreases the priority of an item to the given value.
void increase (const Item &i, const Prio &p)
 Increases the priority of an item to the given value.
State state (const Item &i) const
 Returns if an 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 an item in the heap.


Member Enumeration Documentation

enum State

Each item has a state associated to it. It can be "in heap", "pre heap" or "post heap". The later two are indifferent from the point of view of the heap, but may be useful for the user.

The ItemIntMap must be initialized in such a way, that it assigns PRE_HEAP (-1) to every item.


Constructor & Destructor Documentation

Heap ( ItemIntMap &  map  )  [inline, explicit]

The constructor.

Parameters:
map A map that assigns int values to keys of type Item. It is used internally by the heap implementations to handle the cross references. The assigned value must be PRE_HEAP (-1) for every item.


Member Function Documentation

int size (  )  const [inline]

Returns the number of items stored in the heap.

bool empty (  )  const [inline]

Returns true if the heap is empty.

void clear (  ) 

Makes the heap empty.

void push ( const Item i,
const Prio p 
) [inline]

Inserts the given item into the heap with the given priority.

Parameters:
i The item to insert.
p The priority of the item.

Item top (  )  const [inline]

Returns the item having minimum priority.

Precondition:
The heap must be non-empty.

Prio prio (  )  const [inline]

Returns the minimum priority.

Precondition:
The heap must be non-empty.

void pop (  )  [inline]

Removes the item having minimum priority.

Precondition:
The heap must be non-empty.

void erase ( const Item i  )  [inline]

Removes the given item from the heap if it is already stored.

Parameters:
i The item to delete.

Prio operator[] ( const Item i  )  const [inline]

Returns the priority of the given item.

Precondition:
i must be in the heap.
Parameters:
i The item.

void set ( const Item i,
const Prio p 
) [inline]

This method sets the priority of the given item if it is already stored in the heap. Otherwise it inserts the given item with the given priority.

Parameters:
i The item.
p The priority.

void decrease ( const Item i,
const Prio p 
) [inline]

Decreases the priority of an item to the given value.

Precondition:
i must be stored in the heap with priority at least p.
Parameters:
i The item.
p The priority.

void increase ( const Item i,
const Prio p 
) [inline]

Increases the priority of an item to the given value.

Precondition:
i must be stored in the heap with priority at most p.
Parameters:
i The item.
p The priority.

State state ( const Item i  )  const [inline]

This method returns PRE_HEAP if the given 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 the item will get back to the heap again.

Parameters:
i The item.

void state ( const Item i,
State  st 
) [inline]

Sets the state of the given 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.


The documentation for this class was generated from the following file:

Generated on Thu Mar 26 21:26:33 2009 for LEMON by  doxygen 1.5.8