Changeset 1717:75fe24093ded in lemon-0.x
- Timestamp:
- 10/14/05 12:40:00 (17 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2244
- Location:
- lemon
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/bin_heap.h
r1435 r1717 110 110 bool empty() const { return data.empty(); } 111 111 112 /// \brief Make empty this heap. 113 /// 114 /// Make empty this heap. 115 void clear() { 116 for (int i = 0; i < (int)data.size(); ++i) { 117 iim.set(data[i].first, POST_HEAP); 118 } 119 data.clear(); 120 } 121 112 122 private: 113 123 static int parent(int i) { return (i-1)/2; } -
lemon/concept/heap.h
r1494 r1717 62 62 explicit Heap(ItemIntMap &_iim) {} 63 63 64 /// The number of items stored in the heap.65 /// 66 /// \briefReturns the number of items stored in the heap.64 /// \brief The number of items stored in the heap. 65 /// 66 /// Returns the number of items stored in the heap. 67 67 int size() const { return 0; } 68 68 69 /// \brief Checks if the heap stores no items. 69 70 /// 70 71 /// Returns \c true if and only if the heap stores no items. 71 72 bool empty() const { return false; } 73 74 /// \brief Makes empty this heap. 75 /// 76 /// Makes this heap empty. 77 void clear(); 72 78 73 79 /// \brief Insert an item into the heap with the given heap. … … 190 196 state = _Heap::IN_HEAP; 191 197 state = _Heap::POST_HEAP; 198 199 heap.clear(); 192 200 } 193 201 -
lemon/fib_heap.h
r1435 r1717 89 89 }; 90 90 91 ///The constructor 92 93 /** 94 \c _iimap should be given to the constructor, since it is 95 used internally to handle the cross references. 96 */ 91 /// \brief The constructor 92 /// 93 /// \c _iimap should be given to the constructor, since it is 94 /// used internally to handle the cross references. 97 95 explicit FibHeap(ItemIntMap &_iimap) 98 96 : minimum(0), iimap(_iimap), num_items() {} 99 97 100 ///The constructor 101 102 /** 103 \c _iimap should be given to the constructor, since it is used 104 internally to handle the cross references. \c _comp is an 105 object for ordering of the priorities. 106 */ 98 /// \brief The constructor 99 /// 100 /// \c _iimap should be given to the constructor, since it is used 101 /// internally to handle the cross references. \c _comp is an 102 /// object for ordering of the priorities. 107 103 FibHeap(ItemIntMap &_iimap, const Compare &_comp) : minimum(0), 108 104 iimap(_iimap), comp(_comp), num_items() {} 109 105 110 ///The number of items stored in the heap. 111 112 /** 113 Returns the number of items stored in the heap. 114 */ 106 /// \brief The number of items stored in the heap. 107 /// 108 /// Returns the number of items stored in the heap. 115 109 int size() const { return num_items; } 116 110 117 ///Checks if the heap stores no items. 118 119 /** 120 Returns \c true if and only if the heap stores no items. 121 */ 111 /// \brief Checks if the heap stores no items. 112 /// 113 /// Returns \c true if and only if the heap stores no items. 122 114 bool empty() const { return num_items==0; } 123 115 124 ///\c item gets to the heap with priority \c value independently if \c item was already there. 125 126 /** 127 This method calls \ref push(\c item, \c value) if \c item is not 128 stored in the heap and it calls \ref decrease(\c item, \c value) or 129 \ref increase(\c item, \c value) otherwise. 130 */ 116 /// \brief Make empty this heap. 117 /// 118 /// Make empty this heap. 119 void clear() { 120 for (int i = 0; i < (int)container.size(); ++i) { 121 iimap[container[i].name] = -2; 122 } 123 container.clear(); minimum = 0; num_items = 0; 124 } 125 126 /// \brief \c item gets to the heap with priority \c value independently 127 /// if \c item was already there. 128 /// 129 /// This method calls \ref push(\c item, \c value) if \c item is not 130 /// stored in the heap and it calls \ref decrease(\c item, \c value) or 131 /// \ref increase(\c item, \c value) otherwise. 131 132 void set (Item const item, PrioType const value); 132 133 133 ///Adds \c item to the heap with priority \c value. 134 135 /** 136 Adds \c item to the heap with priority \c value. 137 \pre \c item must not be stored in the heap. 138 */ 134 /// \brief Adds \c item to the heap with priority \c value. 135 /// 136 /// Adds \c item to the heap with priority \c value. 137 /// \pre \c item must not be stored in the heap. 139 138 void push (Item const item, PrioType const value); 140 139 141 ///Returns the item with minimum priority relative to \c Compare. 142 143 /** 144 This method returns the item with minimum priority relative to \c 145 Compare. 146 \pre The heap must be nonempty. 147 */ 140 /// \brief Returns the item with minimum priority relative to \c Compare. 141 /// 142 /// This method returns the item with minimum priority relative to \c 143 /// Compare. 144 /// \pre The heap must be nonempty. 148 145 Item top() const { return container[minimum].name; } 149 146 150 ///Returns the minimum priority relative to \c Compare. 151 152 /** 153 It returns the minimum priority relative to \c Compare. 154 \pre The heap must be nonempty. 155 */ 147 /// \brief Returns the minimum priority relative to \c Compare. 148 /// 149 /// It returns the minimum priority relative to \c Compare. 150 /// \pre The heap must be nonempty. 156 151 PrioType prio() const { return container[minimum].prio; } 157 152 158 ///Returns the priority of \c item. 159 160 /** 161 This function returns the priority of \c item. 162 \pre \c item must be in the heap. 163 */ 153 /// \brief Returns the priority of \c item. 154 /// 155 /// This function returns the priority of \c item. 156 /// \pre \c item must be in the heap. 164 157 PrioType& operator[](const Item& item) { 165 158 return container[iimap[item]].prio; 166 159 } 167 160 168 ///Returns the priority of \c item. 169 170 /** 171 It returns the priority of \c item. 172 \pre \c item must be in the heap. 173 */ 161 /// \brief Returns the priority of \c item. 162 /// 163 /// It returns the priority of \c item. 164 /// \pre \c item must be in the heap. 174 165 const PrioType& operator[](const Item& item) const { 175 166 return container[iimap[item]].prio; … … 177 168 178 169 179 ///Deletes the item with minimum priority relative to \c Compare. 180 181 /** 182 This method deletes the item with minimum priority relative to \c 183 Compare from the heap. 184 \pre The heap must be non-empty. 185 */ 170 /// \brief Deletes the item with minimum priority relative to \c Compare. 171 /// 172 /// This method deletes the item with minimum priority relative to \c 173 /// Compare from the heap. 174 /// \pre The heap must be non-empty. 186 175 void pop(); 187 176 188 ///Deletes \c item from the heap. 189 190 /** 191 This method deletes \c item from the heap, if \c item was already 192 stored in the heap. It is quite inefficient in Fibonacci heaps. 193 */ 177 /// \brief Deletes \c item from the heap. 178 /// 179 /// This method deletes \c item from the heap, if \c item was already 180 /// stored in the heap. It is quite inefficient in Fibonacci heaps. 194 181 void erase (const Item& item); 195 182 196 ///Decreases the priority of \c item to \c value. 197 198 /** 199 This method decreases the priority of \c item to \c value. 200 \pre \c item must be stored in the heap with priority at least \c 201 value relative to \c Compare. 202 */ 183 /// \brief Decreases the priority of \c item to \c value. 184 /// 185 /// This method decreases the priority of \c item to \c value. 186 /// \pre \c item must be stored in the heap with priority at least \c 187 /// value relative to \c Compare. 203 188 void decrease (Item item, PrioType const value); 204 189 205 ///Increases the priority of \c item to \c value. 206 207 /** 208 This method sets the priority of \c item to \c value. Though 209 there is no precondition on the priority of \c item, this 210 method should be used only if it is indeed necessary to increase 211 (relative to \c Compare) the priority of \c item, because this 212 method is inefficient. 213 */ 190 /// \brief Increases the priority of \c item to \c value. 191 /// 192 /// This method sets the priority of \c item to \c value. Though 193 /// there is no precondition on the priority of \c item, this 194 /// method should be used only if it is indeed necessary to increase 195 /// (relative to \c Compare) the priority of \c item, because this 196 /// method is inefficient. 214 197 void increase (Item item, PrioType const value) { 215 198 erase(item); … … 218 201 219 202 220 ///Returns if \c item is in, has already been in, or has never been in the heap. 221 222 /** 223 This method returns PRE_HEAP if \c item has never been in the 224 heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP 225 otherwise. In the latter case it is possible that \c item will 226 get back to the heap again. 227 */ 203 /// \brief Returns if \c item is in, has already been in, or has never 204 /// been in the heap. 205 /// 206 /// This method returns PRE_HEAP if \c item has never been in the 207 /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP 208 /// otherwise. In the latter case it is possible that \c item will 209 /// get back to the heap again. 228 210 state_enum state(const Item &item) const { 229 211 int i=iimap[item]; -
lemon/radix_heap.h
r1435 r1717 27 27 namespace lemon { 28 28 29 /// \addtogroup auxdat30 /// @{31 32 29 /// \brief Exception thrown by RadixHeap. 33 30 /// … … 44 41 }; 45 42 43 /// \ingroup auxdata 44 /// 46 45 /// \brief A Radix Heap implementation. 47 46 /// … … 109 108 /// 110 109 /// The constructor. 111 /// \param _iim should be given to the constructor, since it is used112 /// internally to handle the cross references. The value of the map113 /// should be PRE_HEAP (-1) for each element.114 explicit RadixHeap(ItemIntMap &_iim) : iim(_iim) {115 boxes.push_back(RadixBox(0, 1));116 boxes.push_back(RadixBox(1, 1));117 }118 119 /// \brief The constructor.120 ///121 /// The constructor.122 110 /// 123 111 /// \param _iim It should be given to the constructor, since it is used … … 125 113 /// should be PRE_HEAP (-1) for each element. 126 114 /// 115 /// \param minimal The initial minimal value of the heap. 127 116 /// \param capacity It determines the initial capacity of the heap. 128 RadixHeap(ItemIntMap &_iim, int capacity) : iim(_iim) { 129 boxes.push_back(RadixBox(0, 1)); 130 boxes.push_back(RadixBox(1, 1)); 131 while (upper(boxes.back(), capacity)) { 117 RadixHeap(ItemIntMap &_iim, int minimal = 0, int capacity = 0) 118 : iim(_iim) { 119 boxes.push_back(RadixBox(minimal, 1)); 120 boxes.push_back(RadixBox(minimal + 1, 1)); 121 while (lower(boxes.size() - 1, capacity + minimal - 1)) { 132 122 extend(); 133 123 } … … 142 132 /// Returns \c true if and only if the heap stores no items. 143 133 bool empty() const { return data.empty(); } 134 135 /// \brief Make empty this heap. 136 /// 137 /// Make empty this heap. 138 void clear(int minimal = 0, int capacity = 0) { 139 for (int i = 0; i < (int)data.size(); ++i) { 140 iim[data[i].item] = -2; 141 } 142 data.clear(); boxes.clear(); 143 boxes.push_back(RadixBox(minimal, 1)); 144 boxes.push_back(RadixBox(minimal + 1, 1)); 145 while (lower(boxes.size() - 1, capacity + minimal - 1)) { 146 extend(); 147 } 148 } 144 149 145 150 private: … … 272 277 public: 273 278 274 /// \brief Insert an item into the heap with the given heap.279 /// \brief Insert an item into the heap with the given priority. 275 280 /// 276 281 /// Adds \c i to the heap with priority \c p. … … 293 298 /// \pre The heap must be nonempty. 294 299 Item top() const { 295 const_cast<RadixHeap<Item, ItemIntMap> *>(this)->moveDown();300 const_cast<RadixHeap<Item, ItemIntMap>&>(*this).moveDown(); 296 301 return data[boxes[0].first].item; 297 302 } … … 302 307 /// \pre The heap must be nonempty. 303 308 Prio prio() const { 304 const_cast<RadixHeap<Item, ItemIntMap> *>(this)->moveDown();309 const_cast<RadixHeap<Item, ItemIntMap>&>(*this).moveDown(); 305 310 return data[boxes[0].first].prio; 306 311 }
Note: See TracChangeset
for help on using the changeset viewer.