* This function deletes a node from a partition and reinserts it with * an updated gain **************************************************************************/
| 292 | * an updated gain |
| 293 | **************************************************************************/ |
| 294 | int PQueueUpdate(PQueueType *queue, int node, int oldgain, int newgain) |
| 295 | { |
| 296 | int i, j; |
| 297 | idxtype *locator; |
| 298 | ListNodeType *newnode; |
| 299 | KeyValueType *heap; |
| 300 | |
| 301 | if (oldgain == newgain) |
| 302 | return 0; |
| 303 | |
| 304 | if (queue->type == 1) { |
| 305 | /* First delete the node and then insert it */ |
| 306 | PQueueDelete(queue, node, oldgain); |
| 307 | return PQueueInsert(queue, node, newgain); |
| 308 | } |
| 309 | else { /* Heap Priority Queue */ |
| 310 | heap = queue->heap; |
| 311 | locator = queue->locator; |
| 312 | |
| 313 | ASSERT(locator[node] != -1); |
| 314 | ASSERT(heap[locator[node]].val == node); |
| 315 | ASSERT(heap[locator[node]].key == oldgain); |
| 316 | ASSERT(CheckHeap(queue)); |
| 317 | |
| 318 | i = locator[node]; |
| 319 | |
| 320 | if (oldgain < newgain) { /* Filter-up */ |
| 321 | while (i > 0) { |
| 322 | j = (i-1)>>1; |
| 323 | if (heap[j].key < newgain) { |
| 324 | heap[i] = heap[j]; |
| 325 | locator[heap[i].val] = i; |
| 326 | i = j; |
| 327 | } |
| 328 | else |
| 329 | break; |
| 330 | } |
| 331 | } |
| 332 | else { /* Filter down */ |
| 333 | while ((j=2*i+1) < queue->nnodes) { |
| 334 | if (heap[j].key > newgain) { |
| 335 | if (j+1 < queue->nnodes && heap[j+1].key > heap[j].key) |
| 336 | j = j+1; |
| 337 | heap[i] = heap[j]; |
| 338 | locator[heap[i].val] = i; |
| 339 | i = j; |
| 340 | } |
| 341 | else if (j+1 < queue->nnodes && heap[j+1].key > newgain) { |
| 342 | j = j+1; |
| 343 | heap[i] = heap[j]; |
| 344 | locator[heap[i].val] = i; |
| 345 | i = j; |
| 346 | } |
| 347 | else |
| 348 | break; |
| 349 | } |
| 350 | } |
| 351 |
no test coverage detected