template<typename PR, typename IM, typename CMP>
class lemon::PairingHeap< PR, IM, CMP >
This class implements the pairing heap data structure. It fully conforms to the heap concept.
The methods increase() and erase() are not efficient in a pairing heap. In case of many calls of these operations, it is better to use other heap structure, e.g. binary heap.
- Template Parameters
-
| PR | Type of the priorities of the items. |
| IM | A read-writable item map with int values, used internally to handle the cross references. |
| CMP | A functor class for comparing the priorities. The default is std::less<PR>. |
|
| | PairingHeap (ItemIntMap &map) |
| | Constructor.
|
| |
| | PairingHeap (ItemIntMap &map, const Compare &comp) |
| | Constructor.
|
| |
| int | size () const |
| | The number of items stored in the heap.
|
| |
| bool | empty () const |
| | Check if the heap is empty.
|
| |
| void | clear () |
| | Make the heap empty.
|
| |
| void | set (const Item &item, const Prio &value) |
| | Set the priority of an item or insert it, if it is not stored in the heap.
|
| |
| void | push (const Item &item, const Prio &value) |
| | Insert an item into the heap with the given priority.
|
| |
| Item | top () const |
| | Return the item having minimum priority.
|
| |
| const Prio & | prio () const |
| | The minimum priority.
|
| |
| const Prio & | operator[] (const Item &item) const |
| | The priority of the given item.
|
| |
| void | pop () |
| | Remove the item having minimum priority.
|
| |
| void | erase (const Item &item) |
| | Remove the given item from the heap.
|
| |
| void | decrease (Item item, const Prio &value) |
| | Decrease the priority of an item to the given value.
|
| |
| void | increase (Item item, const Prio &value) |
| | Increase the priority of an item to the given value.
|
| |
| State | state (const Item &item) const |
| | Return the state of an item.
|
| |
| void | state (const Item &i, State st) |
| | Set the state of an item in the heap.
|
| |
template<typename PR , typename IM , typename CMP >
Each item has a state associated to it. It can 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.
|
template<typename PR , typename IM , typename CMP >
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
-