diff -r d8c28868f074 -r 75fe24093ded lemon/radix_heap.h --- a/lemon/radix_heap.h Fri Oct 07 11:05:35 2005 +0000 +++ b/lemon/radix_heap.h Fri Oct 14 10:40:00 2005 +0000 @@ -26,9 +26,6 @@ namespace lemon { - /// \addtogroup auxdat - /// @{ - /// \brief Exception thrown by RadixHeap. /// /// This Exception is thrown when a smaller priority @@ -43,6 +40,8 @@ } }; + /// \ingroup auxdata + /// /// \brief A Radix Heap implementation. /// /// This class implements the \e radix \e heap data structure. A \e heap @@ -108,27 +107,18 @@ /// \brief The constructor. /// /// The constructor. - /// \param _iim should 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. - explicit RadixHeap(ItemIntMap &_iim) : iim(_iim) { - boxes.push_back(RadixBox(0, 1)); - boxes.push_back(RadixBox(1, 1)); - } - - /// \brief The constructor. - /// - /// The constructor. /// /// \param _iim It should 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. /// + /// \param minimal The initial minimal value of the heap. /// \param capacity It determines the initial capacity of the heap. - RadixHeap(ItemIntMap &_iim, int capacity) : iim(_iim) { - boxes.push_back(RadixBox(0, 1)); - boxes.push_back(RadixBox(1, 1)); - while (upper(boxes.back(), capacity)) { + RadixHeap(ItemIntMap &_iim, int minimal = 0, int capacity = 0) + : iim(_iim) { + boxes.push_back(RadixBox(minimal, 1)); + boxes.push_back(RadixBox(minimal + 1, 1)); + while (lower(boxes.size() - 1, capacity + minimal - 1)) { extend(); } } @@ -142,6 +132,21 @@ /// Returns \c true if and only if the heap stores no items. bool empty() const { return data.empty(); } + /// \brief Make empty this heap. + /// + /// Make empty this heap. + void clear(int minimal = 0, int capacity = 0) { + for (int i = 0; i < (int)data.size(); ++i) { + iim[data[i].item] = -2; + } + data.clear(); boxes.clear(); + boxes.push_back(RadixBox(minimal, 1)); + boxes.push_back(RadixBox(minimal + 1, 1)); + while (lower(boxes.size() - 1, capacity + minimal - 1)) { + extend(); + } + } + private: bool upper(int box, Prio prio) { @@ -271,7 +276,7 @@ public: - /// \brief Insert an item into the heap with the given heap. + /// \brief Insert an item into the heap with the given priority. /// /// Adds \c i to the heap with priority \c p. /// \param i The item to insert. @@ -292,7 +297,7 @@ /// This method returns the item with minimum priority. /// \pre The heap must be nonempty. Item top() const { - const_cast*>(this)->moveDown(); + const_cast&>(*this).moveDown(); return data[boxes[0].first].item; } @@ -301,7 +306,7 @@ /// It returns the minimum priority. /// \pre The heap must be nonempty. Prio prio() const { - const_cast*>(this)->moveDown(); + const_cast&>(*this).moveDown(); return data[boxes[0].first].prio; }