----------------- Generic tree operations implementation ----------------- */
| 512 | |
| 513 | /* ----------------- Generic tree operations implementation ----------------- */ |
| 514 | bool flatten_tree(std::unique_ptr<tree_node_t>& root) |
| 515 | { |
| 516 | /* Cannot flatten a view node */ |
| 517 | if (root->as_view_node()) |
| 518 | { |
| 519 | return true; |
| 520 | } |
| 521 | |
| 522 | for (auto it = root->children.begin(); it != root->children.end();) |
| 523 | { |
| 524 | if (!flatten_tree(*it)) |
| 525 | { |
| 526 | it = root->children.erase(it); |
| 527 | } else |
| 528 | { |
| 529 | ++it; |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | if (root->children.empty()) |
| 534 | { |
| 535 | return false; |
| 536 | } |
| 537 | |
| 538 | /* No flattening required on this level */ |
| 539 | if (root->children.size() >= 2) |
| 540 | { |
| 541 | return true; |
| 542 | } |
| 543 | |
| 544 | nonstd::observer_ptr<tree_node_t> child_ptr = {root->children.front()}; |
| 545 | |
| 546 | /* A single view child => cannot make it root */ |
| 547 | if (child_ptr->as_view_node()) |
| 548 | { |
| 549 | if (!root->parent) |
| 550 | { |
| 551 | return true; |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | /* Rewire the tree, skipping the current root */ |
| 556 | child_ptr->parent = root->parent; |
| 557 | root = std::move(root->children.front()); |
| 558 | return true; |
| 559 | } |
| 560 | |
| 561 | nonstd::observer_ptr<split_node_t> get_root( |
| 562 | nonstd::observer_ptr<tree_node_t> node) |
no test coverage detected