Public Types | Public Member Functions

SimpleBucketHeap< IM, MIN > Class Template Reference


Detailed Description

template<typename IM, bool MIN = true>
class lemon::SimpleBucketHeap< IM, MIN >

This class implements a simplified bucket heap data structure. It does not provide some functionality but it faster and simplier data structure than the BucketHeap. The main difference is that the BucketHeap stores for every key a double linked list while this class stores just simple lists. In the other way it does not support erasing each elements just the minimal and it does not supports key increasing, decreasing.

Parameters:
IMA read and write Item int map, used internally to handle the cross references.
MINIf the given parameter is false then instead of the minimum value the maximum can be retrivied with the top() and prio() member functions.
See also:
BucketHeap

#include <lemon/bucket_heap.h>

List of all members.

Public Types

enum  State { IN_HEAP = 0, PRE_HEAP = -1, POST_HEAP = -2 }
 

Type to represent the items states.

More...

Public Member Functions

 SimpleBucketHeap (ItemIntMap &map)
 The constructor.
int size () const
 Returns 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 push (const Pair &p)
 Insert a pair of item and priority into the heap.
void push (const Item &i, const Prio &p)
 Insert an item into the heap with the given priority.
Item top () const
 Returns the item with minimum priority.
Prio prio () const
 Returns the minimum priority.
void pop ()
 Deletes the item with minimum priority.
Prio operator[] (const Item &i) const
 Returns the priority of i.
State state (const Item &i) const
 Returns if item is in, has already been in, or has never been 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

SimpleBucketHeap ( ItemIntMap &  map) [inline, explicit]

The constructor.

Parameters:
mapshould be given to the constructor, since it is used internally to handle the cross references. The value of the map should be PRE_HEAP (-1) for each element.

Member Function Documentation

int size ( ) const [inline]

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 push ( const Pair &  p) [inline]

Adds p.first to the heap with priority p.second.

Parameters:
pThe pair to insert.
void push ( const Item &  i,
const Prio &  p 
) [inline]

Adds i to the heap with priority p.

Parameters:
iThe item to insert.
pThe priority of the item.
Item top ( ) const [inline]

This method returns the item with minimum priority.

Precondition:
The heap must be nonempty.
Prio prio ( ) const [inline]

It returns the minimum priority.

Precondition:
The heap must be nonempty.
void pop ( ) [inline]

This method deletes the item with minimum priority from the heap.

Precondition:
The heap must be non-empty.
Prio operator[] ( const Item &  i) const [inline]

This function returns the priority of item i.

Warning:
This operator is not a constant time function because it scans the whole data structure to find the proper value.
Precondition:
i must be in the heap.
Parameters:
iThe item.
State state ( const Item &  i) 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.

Parameters:
iThe item.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines