MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / treeRemove

Function treeRemove

Engine/source/platform/platformMemory.cpp:618–762  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

616
617#if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
618static void treeRemove(FreeHeader *hdr)
619{
620#ifdef TORQUE_DEBUG_GUARD
621 checkGuard((Header *) hdr, false);
622 setGuard((Header *) hdr, true);
623#endif
624 //validateTree();
625 //gRemoveCount++;
626
627 FreeHeader *prev = hdr->prevQueue;
628 FreeHeader *next = hdr->nextQueue;
629
630 if(prev)
631 prev->nextQueue = next;
632 else
633 hdr->treeNode->queueHead = next;
634
635 if(next)
636 next->prevQueue = prev;
637 else
638 hdr->treeNode->queueTail = prev;
639
640 if(prev || next)
641 return;
642
643 TreeNode *z = hdr->treeNode;
644
645 nil.color = Black;
646
647 TreeNode *y, *x;
648 if(z->left == NIL || z->right == NIL)
649 y = z;
650 else
651 {
652 y = z->right;
653 while(y->left != NIL)
654 y = y->left;
655 }
656 if(y->left != NIL)
657 x = y->left;
658 else
659 x = y->right;
660
661 x->parent = y->parent;
662 if(y->parent == NIL)
663 gFreeTreeRoot = x;
664 else if(y == y->parent->left)
665 y->parent->left = x;
666 else
667 y->parent->right = x;
668
669 U32 yColor = y->color;
670 if(y != z)
671 {
672 // copy y's important fields into z (since we're going to free y)
673 if(z->parent->left == z)
674 z->parent->left = y;
675 else if(z->parent->right == z)

Callers 3

allocFunction · 0.85
freeFunction · 0.85
reallocFunction · 0.85

Calls 5

checkGuardFunction · 0.85
setGuardFunction · 0.85
freeTreeNodeFunction · 0.85
rotateLeftFunction · 0.85
rotateRightFunction · 0.85

Tested by

no test coverage detected