* Insert a new allocation or reservation into the interval tree node `root`. */
| 515 | * Insert a new allocation or reservation into the interval tree node `root`. |
| 516 | */ |
| 517 | static Node *insert(Node *root, intptr_t lb, intptr_t ub, |
| 518 | size_t size, uint32_t flags) |
| 519 | { |
| 520 | if ((intptr_t)size > ub - lb) |
| 521 | return nullptr; |
| 522 | if (root == nullptr) |
| 523 | return node(nullptr, lb, ub, size, flags); |
| 524 | |
| 525 | Node *n = nullptr; |
| 526 | if (size <= root->gap) |
| 527 | { |
| 528 | intptr_t rlb = std::max(lb, root->lb); |
| 529 | intptr_t rub = std::min(ub, root->ub); |
| 530 | if (n == nullptr) |
| 531 | n = insertRightChild(root, rlb, rub, size, flags); |
| 532 | if (n == nullptr) |
| 533 | n = insertLeftChild(root, rlb, rub, size, flags); |
| 534 | } |
| 535 | if (n == nullptr && ub > root->ub) |
| 536 | n = insertRightChild(root, std::max(lb, root->ub), ub, size, flags); |
| 537 | if (n == nullptr && lb < root->lb) |
| 538 | n = insertLeftChild(root, lb, std::min(ub, root->lb), size, flags); |
| 539 | |
| 540 | return n; |
| 541 | } |
| 542 | |
| 543 | /* |
| 544 | * Verify bounds. |
no test coverage detected