template<typename PR, typename IM, typename CMP>
class lemon::BinHeap< PR, IM, CMP >
This class implements the binary heap data structure. It fully conforms to the heap concept.
- 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>. |
|
| | BinHeap (ItemIntMap &map) |
| | Constructor.
|
| |
| | BinHeap (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 | 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 |
| | Return the item having minimum priority.
|
| |
| Prio | prio () const |
| | The minimum priority.
|
| |
| void | pop () |
| | Remove the item having minimum priority.
|
| |
| void | erase (const Item &i) |
| | Remove the given item from the heap.
|
| |
| Prio | operator[] (const Item &i) const |
| | The priority of the given item.
|
| |
| void | set (const Item &i, const Prio &p) |
| | Set the priority of an item or insert it, if it is not stored in the heap.
|
| |
| void | decrease (const Item &i, const Prio &p) |
| | Decrease the priority of an item to the given value.
|
| |
| void | increase (const Item &i, const Prio &p) |
| | Increase the priority of an item to the given value.
|
| |
| State | state (const Item &i) const |
| | Return the state of an item.
|
| |
| void | state (const Item &i, State st) |
| | Set the state of an item in the heap.
|
| |
| void | replace (const Item &i, const Item &j) |
| | Replace 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
-
template<typename PR , typename IM , typename CMP >
| void replace |
( |
const Item & |
i, |
|
|
const Item & |
j |
|
) |
| |
|
inline |
This function replaces item i with item j. Item i must be in the heap, while j must be out of the heap. After calling this method, item i will be out of the heap and j will be in the heap with the same prioriority as item i had before.