MCPcopy Create free account
hub / github.com/GJDuck/e9patch / insert

Function insert

src/e9patch/e9alloc.cpp:517–541  ·  view source on GitHub ↗

* Insert a new allocation or reservation into the interval tree node `root`. */

Source from the content-addressed store, hash-verified

515 * Insert a new allocation or reservation into the interval tree node `root`.
516 */
517static 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.

Callers 4

insertLeftChildFunction · 0.70
insertRightChildFunction · 0.70
allocateFunction · 0.70
reserveFunction · 0.70

Calls 3

nodeFunction · 0.85
insertRightChildFunction · 0.85
insertLeftChildFunction · 0.85

Tested by

no test coverage detected