* This function returns the vertex with the largest gain from a partition * and removes the node from the bucket list **************************************************************************/
| 439 | * and removes the node from the bucket list |
| 440 | **************************************************************************/ |
| 441 | int PQueueGetMax(PQueueType *queue) |
| 442 | { |
| 443 | int vtx, i, j, gain, node; |
| 444 | idxtype *locator; |
| 445 | ListNodeType *tptr; |
| 446 | KeyValueType *heap; |
| 447 | |
| 448 | if (queue->nnodes == 0) |
| 449 | return -1; |
| 450 | |
| 451 | queue->nnodes--; |
| 452 | |
| 453 | if (queue->type == 1) { |
| 454 | tptr = queue->buckets[queue->maxgain]; |
| 455 | queue->buckets[queue->maxgain] = tptr->next; |
| 456 | if (tptr->next != NULL) { |
| 457 | tptr->next->prev = NULL; |
| 458 | } |
| 459 | else { |
| 460 | if (queue->nnodes == 0) { |
| 461 | queue->maxgain = -queue->ngainspan; |
| 462 | } |
| 463 | else |
| 464 | for (; queue->buckets[queue->maxgain]==NULL; queue->maxgain--); |
| 465 | } |
| 466 | |
| 467 | return tptr->id; |
| 468 | } |
| 469 | else { |
| 470 | heap = queue->heap; |
| 471 | locator = queue->locator; |
| 472 | |
| 473 | vtx = heap[0].val; |
| 474 | locator[vtx] = -1; |
| 475 | |
| 476 | if ((i = queue->nnodes) > 0) { |
| 477 | gain = heap[i].key; |
| 478 | node = heap[i].val; |
| 479 | i = 0; |
| 480 | while ((j=2*i+1) < queue->nnodes) { |
| 481 | if (heap[j].key > gain) { |
| 482 | if (j+1 < queue->nnodes && heap[j+1].key > heap[j].key) |
| 483 | j = j+1; |
| 484 | heap[i] = heap[j]; |
| 485 | locator[heap[i].val] = i; |
| 486 | i = j; |
| 487 | } |
| 488 | else if (j+1 < queue->nnodes && heap[j+1].key > gain) { |
| 489 | j = j+1; |
| 490 | heap[i] = heap[j]; |
| 491 | locator[heap[i].val] = i; |
| 492 | i = j; |
| 493 | } |
| 494 | else |
| 495 | break; |
| 496 | } |
| 497 | |
| 498 | heap[i].key = gain; |
no test coverage detected