Changeset 209:765619b7cbb2 in lemon-1.2 for lemon/concepts/heap.h
- Timestamp:
- 07/13/08 20:51:02 (17 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/concepts/heap.h
r203 r209 1 /* -*- C++-*-2 * 3 * This file is a part of LEMON, a generic C++ optimization library 1 /* -*- mode: C++; indent-tabs-mode: nil; -*- 2 * 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 5 * Copyright (C) 2003-2008 … … 53 53 /// the user. 54 54 /// 55 /// The \c ItemIntMap must be initialized in such a way, that it 55 /// The \c ItemIntMap must be initialized in such a way, that it 56 56 /// assigns \c PRE_HEAP (<tt>-1</tt>) to every item. 57 57 enum State { 58 59 60 58 IN_HEAP = 0, 59 PRE_HEAP = -1, 60 POST_HEAP = -2 61 61 }; 62 62 63 63 /// \brief The constructor. 64 64 /// … … 86 86 87 87 /// \brief Inserts an item into the heap with the given priority. 88 /// 89 /// Inserts the given item into the heap with the given priority. 88 /// 89 /// Inserts the given item into the heap with the given priority. 90 90 /// \param i The item to insert. 91 91 /// \param p The priority of the item. … … 113 113 /// 114 114 /// Removes the given item from the heap if it is already stored. 115 /// \param i The item to delete. 115 /// \param i The item to delete. 116 116 void erase(const Item &i) {} 117 117 118 118 /// \brief The priority of an item. 119 119 /// 120 /// Returns the priority of the given item. 120 /// Returns the priority of the given item. 121 121 /// \pre \c i must be in the heap. 122 122 /// \param i The item. … … 134 134 /// \param p The priority. 135 135 void set(const Item &i, const Prio &p) {} 136 136 137 137 /// \brief Decreases the priority of an item to the given value. 138 138 /// … … 175 175 struct Constraints { 176 176 public: 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 177 void constraints() { 178 typedef typename _Heap::Item OwnItem; 179 typedef typename _Heap::Prio OwnPrio; 180 typedef typename _Heap::State OwnState; 181 182 Item item; 183 Prio prio; 184 item=Item(); 185 prio=Prio(); 186 ignore_unused_variable_warning(item); 187 ignore_unused_variable_warning(prio); 188 189 OwnItem own_item; 190 OwnPrio own_prio; 191 OwnState own_state; 192 own_item=Item(); 193 own_prio=Prio(); 194 ignore_unused_variable_warning(own_item); 195 ignore_unused_variable_warning(own_prio); 196 ignore_unused_variable_warning(own_state); 197 198 _Heap heap1(map); 199 _Heap heap2 = heap1; 200 ignore_unused_variable_warning(heap1); 201 ignore_unused_variable_warning(heap2); 202 203 int s = heap.size(); 204 ignore_unused_variable_warning(s); 205 bool e = heap.empty(); 206 ignore_unused_variable_warning(e); 207 208 prio = heap.prio(); 209 item = heap.top(); 210 prio = heap[item]; 211 own_prio = heap.prio(); 212 own_item = heap.top(); 213 own_prio = heap[own_item]; 214 215 heap.push(item, prio); 216 heap.push(own_item, own_prio); 217 heap.pop(); 218 219 heap.set(item, prio); 220 heap.decrease(item, prio); 221 heap.increase(item, prio); 222 heap.set(own_item, own_prio); 223 heap.decrease(own_item, own_prio); 224 heap.increase(own_item, own_prio); 225 226 heap.erase(item); 227 heap.erase(own_item); 228 heap.clear(); 229 230 own_state = heap.state(own_item); 231 heap.state(own_item, own_state); 232 233 own_state = _Heap::PRE_HEAP; 234 own_state = _Heap::IN_HEAP; 235 own_state = _Heap::POST_HEAP; 236 } 237 238 _Heap& heap; 239 ItemIntMap& map; 240 240 }; 241 241 };
Note: See TracChangeset
for help on using the changeset viewer.