0
2
0
... | ... |
@@ -221,96 +221,98 @@ |
221 | 221 |
//break; |
222 | 222 |
} else { |
223 | 223 |
if( container[ch].left_child ) { |
224 | 224 |
child_right=container[ch].parent; |
225 | 225 |
container[ch].parent = i; |
226 | 226 |
--container[i].degree; |
227 | 227 |
} |
228 | 228 |
else { |
229 | 229 |
child_right=ch; |
230 | 230 |
container[i].child=-1; |
231 | 231 |
container[i].degree=0; |
232 | 232 |
} |
233 | 233 |
container[child_right].parent = -1; |
234 | 234 |
TreeArray[num_child] = child_right; |
235 | 235 |
i = child_right; |
236 | 236 |
++num_child; |
237 | 237 |
} |
238 | 238 |
} |
239 | 239 |
|
240 | 240 |
int other; |
241 | 241 |
for( i=0; i<num_child-1; i+=2 ) { |
242 | 242 |
if ( !comp(container[TreeArray[i]].prio, |
243 | 243 |
container[TreeArray[i+1]].prio) ) { |
244 | 244 |
other=TreeArray[i]; |
245 | 245 |
TreeArray[i]=TreeArray[i+1]; |
246 | 246 |
TreeArray[i+1]=other; |
247 | 247 |
} |
248 | 248 |
fuse( TreeArray[i], TreeArray[i+1] ); |
249 | 249 |
} |
250 | 250 |
|
251 | 251 |
i = (0==(num_child % 2)) ? num_child-2 : num_child-1; |
252 | 252 |
while(i>=2) { |
253 | 253 |
if ( comp(container[TreeArray[i]].prio, |
254 | 254 |
container[TreeArray[i-2]].prio) ) { |
255 | 255 |
other=TreeArray[i]; |
256 | 256 |
TreeArray[i]=TreeArray[i-2]; |
257 | 257 |
TreeArray[i-2]=other; |
258 | 258 |
} |
259 | 259 |
fuse( TreeArray[i-2], TreeArray[i] ); |
260 | 260 |
i-=2; |
261 | 261 |
} |
262 | 262 |
minimum = TreeArray[0]; |
263 | 263 |
} |
264 | 264 |
|
265 | 265 |
if ( 0==num_child ) { |
266 | 266 |
minimum = container[minimum].child; |
267 | 267 |
} |
268 | 268 |
|
269 |
if (minimum >= 0) container[minimum].left_child = false; |
|
270 |
|
|
269 | 271 |
--num_items; |
270 | 272 |
} |
271 | 273 |
|
272 | 274 |
/// \brief Deletes \c item from the heap. |
273 | 275 |
/// |
274 | 276 |
/// This method deletes \c item from the heap, if \c item was already |
275 | 277 |
/// stored in the heap. It is quite inefficient in Pairing heaps. |
276 | 278 |
void erase (const Item& item) { |
277 | 279 |
int i=iimap[item]; |
278 | 280 |
if ( i>=0 && container[i].in ) { |
279 | 281 |
decrease( item, container[minimum].prio-1 ); |
280 | 282 |
pop(); |
281 | 283 |
} |
282 | 284 |
} |
283 | 285 |
|
284 | 286 |
/// \brief Decreases the priority of \c item to \c value. |
285 | 287 |
/// |
286 | 288 |
/// This method decreases the priority of \c item to \c value. |
287 | 289 |
/// \pre \c item must be stored in the heap with priority at least \c |
288 | 290 |
/// value relative to \c Compare. |
289 | 291 |
void decrease (Item item, const Prio& value) { |
290 | 292 |
int i=iimap[item]; |
291 | 293 |
container[i].prio=value; |
292 | 294 |
int p=container[i].parent; |
293 | 295 |
|
294 | 296 |
if( container[i].left_child && i!=container[p].child ) { |
295 | 297 |
p=container[p].parent; |
296 | 298 |
} |
297 | 299 |
|
298 | 300 |
if ( p!=-1 && comp(value,container[p].prio) ) { |
299 | 301 |
cut(i,p); |
300 | 302 |
if ( comp(container[minimum].prio,value) ) { |
301 | 303 |
fuse(minimum,i); |
302 | 304 |
} else { |
303 | 305 |
fuse(i,minimum); |
304 | 306 |
minimum=i; |
305 | 307 |
} |
306 | 308 |
} |
307 | 309 |
} |
308 | 310 |
|
309 | 311 |
/// \brief Increases the priority of \c item to \c value. |
310 | 312 |
/// |
311 | 313 |
/// This method sets the priority of \c item to \c value. Though |
312 | 314 |
/// there is no precondition on the priority of \c item, this |
313 | 315 |
/// method should be used only if it is indeed necessary to increase |
314 | 316 |
/// (relative to \c Compare) the priority of \c item, because this |
315 | 317 |
/// method is inefficient. |
316 | 318 |
void increase (Item item, const Prio& value) { |
... | ... |
@@ -177,100 +177,100 @@ |
177 | 177 |
{ |
178 | 178 |
typedef BinHeap<Prio, ItemIntMap> IntHeap; |
179 | 179 |
checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); |
180 | 180 |
heapSortTest<IntHeap>(); |
181 | 181 |
heapIncreaseTest<IntHeap>(); |
182 | 182 |
|
183 | 183 |
typedef BinHeap<Prio, IntNodeMap > NodeHeap; |
184 | 184 |
checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>(); |
185 | 185 |
dijkstraHeapTest<NodeHeap>(digraph, length, source); |
186 | 186 |
} |
187 | 187 |
|
188 | 188 |
// FouraryHeap |
189 | 189 |
{ |
190 | 190 |
typedef FouraryHeap<Prio, ItemIntMap> IntHeap; |
191 | 191 |
checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); |
192 | 192 |
heapSortTest<IntHeap>(); |
193 | 193 |
heapIncreaseTest<IntHeap>(); |
194 | 194 |
|
195 | 195 |
typedef FouraryHeap<Prio, IntNodeMap > NodeHeap; |
196 | 196 |
checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>(); |
197 | 197 |
dijkstraHeapTest<NodeHeap>(digraph, length, source); |
198 | 198 |
} |
199 | 199 |
|
200 | 200 |
// KaryHeap |
201 | 201 |
{ |
202 | 202 |
typedef KaryHeap<Prio, ItemIntMap> IntHeap; |
203 | 203 |
checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); |
204 | 204 |
heapSortTest<IntHeap>(); |
205 | 205 |
heapIncreaseTest<IntHeap>(); |
206 | 206 |
|
207 | 207 |
typedef KaryHeap<Prio, IntNodeMap > NodeHeap; |
208 | 208 |
checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>(); |
209 | 209 |
dijkstraHeapTest<NodeHeap>(digraph, length, source); |
210 | 210 |
} |
211 | 211 |
|
212 | 212 |
// FibHeap |
213 | 213 |
{ |
214 | 214 |
typedef FibHeap<Prio, ItemIntMap> IntHeap; |
215 | 215 |
checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); |
216 | 216 |
heapSortTest<IntHeap>(); |
217 | 217 |
heapIncreaseTest<IntHeap>(); |
218 | 218 |
|
219 | 219 |
typedef FibHeap<Prio, IntNodeMap > NodeHeap; |
220 | 220 |
checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>(); |
221 | 221 |
dijkstraHeapTest<NodeHeap>(digraph, length, source); |
222 | 222 |
} |
223 | 223 |
|
224 | 224 |
// PairingHeap |
225 |
// { |
|
226 |
// typedef PairingHeap<Prio, ItemIntMap> IntHeap; |
|
227 |
// checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); |
|
228 |
// heapSortTest<IntHeap>(); |
|
229 |
// heapIncreaseTest<IntHeap>(); |
|
230 |
// |
|
231 |
// typedef PairingHeap<Prio, IntNodeMap > NodeHeap; |
|
232 |
// checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>(); |
|
233 |
// dijkstraHeapTest<NodeHeap>(digraph, length, source); |
|
234 |
// } |
|
225 |
{ |
|
226 |
typedef PairingHeap<Prio, ItemIntMap> IntHeap; |
|
227 |
checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); |
|
228 |
heapSortTest<IntHeap>(); |
|
229 |
heapIncreaseTest<IntHeap>(); |
|
230 |
|
|
231 |
typedef PairingHeap<Prio, IntNodeMap > NodeHeap; |
|
232 |
checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>(); |
|
233 |
dijkstraHeapTest<NodeHeap>(digraph, length, source); |
|
234 |
} |
|
235 | 235 |
|
236 | 236 |
// RadixHeap |
237 | 237 |
{ |
238 | 238 |
typedef RadixHeap<ItemIntMap> IntHeap; |
239 | 239 |
checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); |
240 | 240 |
heapSortTest<IntHeap>(); |
241 | 241 |
heapIncreaseTest<IntHeap>(); |
242 | 242 |
|
243 | 243 |
typedef RadixHeap<IntNodeMap > NodeHeap; |
244 | 244 |
checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>(); |
245 | 245 |
dijkstraHeapTest<NodeHeap>(digraph, length, source); |
246 | 246 |
} |
247 | 247 |
|
248 | 248 |
// BinomHeap |
249 | 249 |
{ |
250 | 250 |
typedef BinomHeap<Prio, ItemIntMap> IntHeap; |
251 | 251 |
checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); |
252 | 252 |
heapSortTest<IntHeap>(); |
253 | 253 |
heapIncreaseTest<IntHeap>(); |
254 | 254 |
|
255 | 255 |
typedef BinomHeap<Prio, IntNodeMap > NodeHeap; |
256 | 256 |
checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>(); |
257 | 257 |
dijkstraHeapTest<NodeHeap>(digraph, length, source); |
258 | 258 |
} |
259 | 259 |
|
260 | 260 |
// BucketHeap, SimpleBucketHeap |
261 | 261 |
{ |
262 | 262 |
typedef BucketHeap<ItemIntMap> IntHeap; |
263 | 263 |
checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); |
264 | 264 |
heapSortTest<IntHeap>(); |
265 | 265 |
heapIncreaseTest<IntHeap>(); |
266 | 266 |
|
267 | 267 |
typedef BucketHeap<IntNodeMap > NodeHeap; |
268 | 268 |
checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>(); |
269 | 269 |
dijkstraHeapTest<NodeHeap>(digraph, length, source); |
270 | 270 |
|
271 | 271 |
typedef SimpleBucketHeap<ItemIntMap> SimpleIntHeap; |
272 | 272 |
heapSortTest<SimpleIntHeap>(); |
273 | 273 |
} |
274 | 274 |
|
275 | 275 |
return 0; |
276 | 276 |
} |
0 comments (0 inline)