* @brief Insert a partitioning into an order list of results, sorted by error. * * @param max_values The max number of entries in the best result arrays. * @param this_error The error of the new entry. * @param this_partition The partition ID of the new entry. * @param[out] best_errors The array of best error values. * @param[out] best_partitions The array of be
| 510 | * @param[out] best_partitions The array of best partition values. |
| 511 | */ |
| 512 | static void insert_result( |
| 513 | unsigned int max_values, |
| 514 | float this_error, |
| 515 | unsigned int this_partition, |
| 516 | float* best_errors, |
| 517 | unsigned int* best_partitions) |
| 518 | { |
| 519 | promise(max_values > 0); |
| 520 | |
| 521 | // Don't bother searching if the current worst error beats the new error |
| 522 | if (this_error >= best_errors[max_values - 1]) |
| 523 | { |
| 524 | return; |
| 525 | } |
| 526 | |
| 527 | // Else insert into the list in error-order |
| 528 | for (unsigned int i = 0; i < max_values; i++) |
| 529 | { |
| 530 | // Existing result is better - move on ... |
| 531 | if (this_error > best_errors[i]) |
| 532 | { |
| 533 | continue; |
| 534 | } |
| 535 | |
| 536 | // Move existing results down one |
| 537 | for (unsigned int j = max_values - 1; j > i; j--) |
| 538 | { |
| 539 | best_errors[j] = best_errors[j - 1]; |
| 540 | best_partitions[j] = best_partitions[j - 1]; |
| 541 | } |
| 542 | |
| 543 | // Insert new result |
| 544 | best_errors[i] = this_error; |
| 545 | best_partitions[i] = this_partition; |
| 546 | break; |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | /* See header for documentation. */ |
| 551 | unsigned int find_best_partition_candidates( |
no outgoing calls
no test coverage detected