MCPcopy Create free account
hub / github.com/acm-clan/algorithm-stone / RBTreeNode

Class RBTreeNode

templates/rb.cpp:24–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22
23public:
24 struct RBTreeNode {
25 int k = 0;
26 int v = 0;
27 RBTreeNode* p = nullptr;
28 RBTreeNode* left = nullptr;
29 RBTreeNode* right = nullptr;
30 Color color = RED;
31
32 RBTreeNode(int k, int v, Color color)
33 : k(k)
34 , v(v)
35 , color(color)
36 {
37 left = NIL;
38 right = NIL;
39 p = NIL;
40 }
41
42 void setLeft(RBTreeNode* n)
43 {
44 if (n == nullptr) {
45 printf("wrong left\n");
46 }
47 this->left = n;
48 }
49
50 void setRight(RBTreeNode* n)
51 {
52 if (n == nullptr) {
53 printf("wrong left\n");
54 }
55 right = n;
56 }
57
58 bool isLeft()
59 {
60 return this == p->left;
61 }
62
63 bool isRight()
64 {
65 return this == p->right;
66 }
67
68 RBTreeNode* brother()
69 {
70 return isLeft() ? p->right : p->left;
71 }
72
73 void replaceChild(RBTreeNode* n, RBTreeNode* new_node)
74 {
75 if (n == left) {
76 left = new_node;
77 } else {
78 right = new_node;
79 }
80 new_node->p = this;
81 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected