SimpleBucketHeap
Declared in lemon/bucket_heap.h, in the group Heap Structures; the same class on the Doxygen site.
-
template< typename IM , bool MIN = true >
class SimpleBucketHeap Simplified bucket heap data structure.
This class implements a simplified bucket heap data structure. It does not provide some functionality, but it is faster and simpler than BucketHeap. The main difference is that BucketHeap stores a doubly-linked list for each key while this class stores only simply-linked lists. It supports erasing only for the item having minimum priority and it does not support key increasing and decreasing.
Note that this implementation does not conform to the heap concept due to the lack of some functionality.
See also
- Template Parameters:
IM – A reference item map with
intvalues (one whoseoperator[] gives a reference, which the heap writes through), used internally to handle the cross references.MIN – Indicate if the heap is a min-heap or a max-heap. The default is min-heap. If this parameter is set to
false, then the comparison is reversed, so the top(), prio() and pop() functions deal with the item having maximum priority instead of the minimum.
Public Types
-
enum State
Type to represent the states of the items.
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.Values:
-
enumerator IN_HEAP
= 0.
-
enumerator PRE_HEAP
= -1.
-
enumerator POST_HEAP
= -2.
-
enumerator IN_HEAP
-
typedef int Prio
Type of the priorities.
-
typedef ItemIntMap::Key Item
Type of the items stored in the heap.
Public Functions
-
inline explicit SimpleBucketHeap( ItemIntMap & map )
Constructor.
- Parameters:
map – A map that assigns
intvalues to the items. It is used internally to handle the cross references. The assigned value must bePRE_HEAP(-1) for each item.
-
inline int size() const
The number of items stored in the heap.
This function returns the number of items stored in the heap.
-
inline bool empty() const
Check if the heap is empty.
This function returns
trueif the heap is empty.
-
inline void clear()
Make the heap empty.
This functon makes the heap empty. It does not change the cross reference map. If you want to reuse a heap that is not surely empty, you should first clear it and then you should set the cross reference map to
PRE_HEAPfor each item.
-
inline void push( const Pair & p )
Insert a pair of item and priority into the heap.
This function inserts
p.firstto the heap with priorityp.second.- Parameters:
p – The pair to insert.
- Pre:
p.firstmust not be stored in the heap.
-
inline void push( const Item & i , const Prio & p )
Insert an item into the heap with the given priority.
This function inserts the given item into the heap with the given priority.
- Parameters:
i – The item to insert.
p – The priority of the item.
- Pre:
i must not be stored in the heap.
-
inline Item top() const
Return the item having minimum priority.
This function returns the item having minimum priority.
- Pre:
The heap must be non-empty.
-
inline Prio prio() const
The minimum priority.
This function returns the minimum priority.
- Pre:
The heap must be non-empty.
-
inline void pop()
Remove the item having minimum priority.
This function removes the item having minimum priority.
- Pre:
The heap must be non-empty.
-
inline Prio operator[]( const Item & i ) const
The priority of the given item.
This function returns the priority of the given item.
Warning
This operator is not a constant time function because it scans the whole data structure to find the proper value.
- Parameters:
i – The item.
- Pre:
i must be in the heap.
-
inline State state( const Item & i ) const
Return the state of an item.
This method returns
PRE_HEAPif the given item has never been in the heap,IN_HEAPif it is in the heap at the moment, andPOST_HEAPotherwise. In the latter case it is possible that the item will get back to the heap again.- Parameters:
i – The item.