void insert_case5(GtkWidget *darea, rbtree t, node n) { n->parent->color = BLACK; grandparent(n)->color = RED; if (n == n->parent->left && n->parent == grandparent(n)->left) rotate_right(darea, t, grandparent(n)); else rotate_left(darea, t, grandparent(n)); }
void insert_case4(rbtree t, node n) { if (n == n->parent->right && n->parent == grandparent(n)->left) { rotate_left(t, n->parent); n = n->left; } else if (n == n->parent->left && n->parent == grandparent(n)->right) { rotate_right(t, n->parent); n = n->right; } insert_case5(t, n); }
void insert_case5(rbtree t, node n) { n->parent->color = BLACK; grandparent(n)->color = RED; if (n == n->parent->left && n->parent == grandparent(n)->left) { rotate_right(t, grandparent(n)); } else { assert (n == n->parent->right && n->parent == grandparent(n)->right); rotate_left(t, grandparent(n)); } }
void insertCase4(rbTree tree, rbTreeNode node) { if (node == node->parent->right && node->parent == grandparent(node)->left) { rbRotateLeft(tree, node->parent); node = node->left; } else if (node == node->parent->left && node->parent == grandparent(node)->right) { rbRotateRight(tree, node->parent); node = node->right; } insertCase5(tree, node); }
void insertCase3(rbTree tree, rbTreeNode node) { if (nodeColor(uncle(node)) == 1) { //RED node->parent->color = 0; //BLACK uncle(node)->color = 0; //BLACK grandparent(node)->color = 1; //RED insertCase1(tree, grandparent(node)); } else { insertCase4(tree, node); } }
void insertCase5(rbTree tree, rbTreeNode node) { node->parent->color = 0; //BLACK grandparent(node)->color = 1; //RED if (node == node->parent->left && node->parent == grandparent(node)->left) { rbRotateRight(tree, grandparent(node)); } else { assert (node == node->parent->right && node->parent == grandparent(node)->right); rbRotateLeft(tree, grandparent(node)); } }
static void insert_case3(L_RBTREE *t, node *n) { if (node_color(uncle(n)) == L_RED_NODE) { n->parent->color = L_BLACK_NODE; uncle(n)->color = L_BLACK_NODE; grandparent(n)->color = L_RED_NODE; insert_case1(t, grandparent(n)); } else { insert_case4(t, n); } }
static void insert_case4(L_RBTREE *t, node *n) { if (n == n->parent->right && n->parent == grandparent(n)->left) { rotate_left(t, n->parent); n = n->left; } else if (n == n->parent->left && n->parent == grandparent(n)->right) { rotate_right(t, n->parent); n = n->right; } insert_case5(t, n); }
void insert_case3(rbtree t, node n) { if (node_color(uncle(n)) == RED) { n->parent->color = BLACK; uncle(n)->color = BLACK; grandparent(n)->color = RED; insert_case1(t, grandparent(n)); } else { insert_case4(t, n); } }
static void insert_case5(L_RBTREE *t, node *n) { n->parent->color = L_BLACK_NODE; grandparent(n)->color = L_RED_NODE; if (n == n->parent->left && n->parent == grandparent(n)->left) { rotate_right(t, grandparent(n)); } else if (n == n->parent->right && n->parent == grandparent(n)->right) { rotate_left(t, grandparent(n)); } else { L_ERROR("identity confusion\n", "insert_case5"); } }
void restore_properties(Node *node) { if (parent(node) == nullptr) // Cenário A: node é a raiz node->color = Node::BLACK; else if (parent(node)->color == Node::BLACK) // Cenário B return; else if (uncle(node) and uncle(node)->color == Node::RED) { // Cenário C: pai e tio vermelhos parent(node)->color = Node::BLACK; uncle(node)->color = Node::BLACK; grandparent(node)->color = Node::RED; // Como o pai é vermelho, o avô não é nulo restore_properties(grandparent(node)); } else { // Cenário D: pai vermelho, tio preto auto C = node; auto P = parent(node); auto G = grandparent(node); if (C == P->right and P == G->left) { rotate_left(G, P, C); P = C; } else if (node == P->left and P == G->right) { rotate_right(G, P, C); P = C; } C = P; P = G; G = parent(P); if (C == P->left) rotate_right(G, P, C); else rotate_left(G, P, C); // Corner case: após a rotação C é a nova raiz if (G == nullptr) root = C; C->color = Node::BLACK; P->color = Node::RED; } }
// 노드와 부모 노드의 위치를 오른쪽으로 돌림 void rotateRight(Tree *RBT, Node *node) { Node *p = node->parent; Node *g = grandparent(node); Node *temp = node->right; // 부모가 루트 노드인 경우 if (g == NULL) { RBT->root = node; } else { if (p == g->left) g->left = node; else g->right = node; } node->parent = g; node->right = p; p->parent = node; p->left = temp; temp->parent = p; }
struct RBNode *uncle(struct RBNode *node) { struct RBNode *g = grandparent(node); if (!g) return NULL; return node->parent == g->left ? g->right : g->left; }
void rb_tree_insert_repair(tree_t *tree, node_t *n) { // przypadek 1: korzeń if (is_nil(parent(n))) { n->color = BLACK; return; } // przypadek 2: rodzic czarny if (parent(n)->color == BLACK) return; // przypadek 3: rodzic czerwony; wuj czerwony; if (!is_nil(uncle(n)) && uncle(n)->color == RED) { parent(n)->color = BLACK; uncle(n)->color = BLACK; grandparent(n)->color = RED; rb_tree_insert_repair(tree, grandparent(n)); } else // przypadek 4: rodzic czerwony; wuj czarny; { if (is_right_child(n) && is_left_child(parent(n))) { node_rotate_left(tree, parent(n)); n = n->left; } else if (is_left_child(n) && is_right_child(parent(n))) { node_rotate_right(tree, parent(n)); n = n->right; } // case 5: wuj czarny; nowy, rodzic, dziadek na prostej; nowy i rodzic czerwoni; parent(n)->color = BLACK; grandparent(n)->color = RED; if (is_left_child(n) && is_left_child(parent(n))) node_rotate_right(tree, grandparent(n)); else node_rotate_left(tree, grandparent(n)); } }
rb_node* uncle(rb_node* n) { rb_node* g = grandparent(n); if (g == NULL) return NULL; // No grandparent means no uncle if (n->parent == g->left) return g->right; else return g->left; }
void reconstruct(struct rbt *tree, struct node *node) { if(grandparent(node)->left != tree->nil){ if (grandparent(node)->left->left == node) leftLeftCase(tree, node); else if (grandparent(node)->left->right == node) leftRightCase(tree, node); } else if(grandparent(node)->right != tree->nil){ if(grandparent(node)->right->right == node) rightRightCase(tree, node); else rightLeftCase(tree, node); } }
Step::Step( Where &topOfStep, AbstractStepsElement *_parent, int num, // step number as seen by the user Meta &meta, // the current state of the meta-commands bool calledOut, // if we're a callout bool multiStep) // we can't be a multi-step : calledOut(calledOut) { top = topOfStep; parent = _parent; submodelLevel = meta.submodelStack.size(); stepNumber.number = num; // record step number relativeType = StepType; csiPlacement.relativeType = CsiType; stepNumber.relativeType = StepNumberType; csiItem = NULL; if (calledOut) { csiPlacement.margin = meta.LPub.callout.csi.margin; // assembly meta's csiPlacement.placement = meta.LPub.callout.csi.placement; pli.margin = meta.LPub.callout.pli.margin; // PLI info pli.placement = meta.LPub.callout.pli.placement; stepNumber.placement = meta.LPub.callout.stepNum.placement; stepNumber.font = meta.LPub.callout.stepNum.font.valueFoo(); stepNumber.color = meta.LPub.callout.stepNum.color.value(); stepNumber.margin = meta.LPub.callout.stepNum.margin; pliPerStep = meta.LPub.callout.pli.perStep.value(); } else if (multiStep) { csiPlacement.margin = meta.LPub.multiStep.csi.margin; // assembly meta's csiPlacement.placement = meta.LPub.multiStep.csi.placement; pli.margin = meta.LPub.multiStep.pli.margin; pli.placement = meta.LPub.multiStep.pli.placement; stepNumber.placement = meta.LPub.multiStep.stepNum.placement; stepNumber.font = meta.LPub.multiStep.stepNum.font.valueFoo(); stepNumber.color = meta.LPub.multiStep.stepNum.color.value(); stepNumber.margin = meta.LPub.multiStep.stepNum.margin; pliPerStep = meta.LPub.multiStep.pli.perStep.value(); } else { csiPlacement.margin = meta.LPub.assem.margin; // assembly meta's csiPlacement.placement = meta.LPub.assem.placement; pli.margin = meta.LPub.assem.margin; pli.placement = meta.LPub.pli.placement; stepNumber.font = meta.LPub.stepNumber.font.valueFoo(); stepNumber.color = meta.LPub.stepNumber.color.value(); stepNumber.margin = meta.LPub.stepNumber.margin; stepNumber.placement = meta.LPub.stepNumber.placement; stepNumber.margin = meta.LPub.stepNumber.margin; pliPerStep = false; } pli.steps = grandparent(); pli.step = this; }
RBNode* RBTree::uncle(RBNode* n) { RBNode* g = grandparent(n); if( g == 0) return 0; if(n->father->getKey()== g->left->getKey() ) return g->right; else return g->left; }
static void rb_insert_fixup(struct redblack_tree *T, struct rb_node *z) { struct rb_node *g, *y; while (z->parent->color == RED) { /* parent is never null */ g = grandparent(z); if (z->parent == g->left) { y = g->right; /* Uncle */ if (y->color == RED) { z->parent->color = BLACK; y->color = BLACK; g->color = RED; z = g; } else { if (z == z->parent->right) { z = z->parent; rotate_left(T, z); g = grandparent(z); /* New grand parent */ } z->parent->color = BLACK; g->color = RED; rotate_right(T, g); } } else { /* Same as first part with "right" and "left" exchanged */ y = g->left; if (y->color == RED) { z->parent->color = BLACK; y->color = BLACK; g->color = RED; z = g; } else { if (z == z->parent->left) { z = z->parent; rotate_right(T, z); g = grandparent(z); } z->parent->color = BLACK; g->color = RED; rotate_left(T, g); } } } T->root->color = BLACK; }
//Caso 5 void RBTree::fixup_case5(RBNode* n){ RBNode* abuelo = grandparent(n); n->father->setColor( NEGRO ); abuelo->setColor( ROJO ); if (n == n->father->left) right_rotate(abuelo); else left_rotate(abuelo); }
void correctDoubleRed(struct rbt *tree, struct node *node) { if(isRoot(tree, node->parent)) return; if(node->parent->color != RED) return; if(siblingColor(node->parent) != RED){ reconstruct(tree, node); } else { changeColor(tree, node->parent, BLACK); changeColor(tree, sibling_node(node->parent), BLACK); if(isRoot(tree, grandparent(node))) return; changeColor(tree, grandparent(node), RED); correctDoubleRed(tree, grandparent(node)); } }
void pdf_format::stack_event(stream_type& os, bool is_push) { const format_element_t& top(stack_top()); name_t self(top.tag()); name_t parent(stack_depth() >= 2 ? stack_n(1).tag() : name_t()); name_t grandparent(stack_depth() >= 3 ? stack_n(2).tag() : name_t()); if (self == atom_name_g) { handle_atom(os, is_push); } else if (is_push) { if (self == static_name_t("pdf")) { os << "% start pdf" << std::endl; } else if (self == bag_name_g) { os << "<<"; up(); } else if (self == seq_name_g && parent != bag_name_g) { os << "[ "; } } else { if (self == static_name_t("pdf")) { os << "\n% end pdf"; } else if (self == bag_name_g) { down(); if (top.num_out_m > 0) os << '\n' << indents(depth()); else os << ' '; os << ">>"; } else if (self == seq_name_g && parent != bag_name_g) { if (top.num_out_m > 0) os << ' '; os << ']'; } } }
void insert_case5(rb_node* n, rb_tree* tree) { rb_node* g = grandparent(n); n->parent->color = BLACK; g->color = RED; if ((n == n->parent->left) && (n->parent == g->left)) { rotate_right(g, tree); } else if ((n == n->parent->right) && (n->parent == g->right)) { rotate_left(g, tree); } }
// 현재 노드의 부모의 형제 노드 Node *uncle(Node *node) { Node *g = grandparent(node); if (g == NULL) return NULL; if (node->parent == g->left) return g->right; else return g->left; }
static inline struct RBTREE_NODE* uncle(struct RBTREE_NODE* entry) { struct RBTREE_NODE* g = grandparent(entry); if (g == NULL) return NULL; // No grandparent means no uncle if (entry->parent == g->left) return g->right; else return g->left; }
static qrb_node *uncle( qrb_node *np ) { qrb_node *g_p; g_p = grandparent(np); if( g_p == NULL ) return NULL; if( np->parent == g_p->left ) return g_p->right; else return g_p->left; }
void Heap::bubbleUpMax(int i) { int g = grandparent(i); if(g >= 0) { if(heap[i] > heap[g]) { swap(i, g); bubbleUpMax(g); } } }
static void insert_case5(struct RBTREE_TYPENAME* target, struct RBTREE_NODE* node) { struct RBTREE_NODE* g = grandparent(node); node->parent->color = BLACK; g->color = RED; if (node == node->parent->left) rotate_right(target, g); else rotate_left(target, g); }
void insert_case4(rb_node* n, rb_tree* tree) { rb_node* g = grandparent(n); if ((n == n->parent->right) && (n->parent == g->left)) { rotate_left(n->parent, tree); n = n->left; } else if ((n == n->parent->left) && (n->parent == g->right)) { rotate_right(n->parent, tree); n = n->right; } insert_case5(n, tree); }
void leftLeftCase(struct rbt *tree, struct node *node) { struct node *tmp = grandparent(node)->parent; grandparent(node)->left = node->parent->right; if (grandparent(node)->left != tree->nil) grandparent(node)->left->parent = grandparent(node); node->parent->right = grandparent(node); grandparent(node)->parent = node->parent; node->parent->parent = tmp; if(!isRoot(tree, node->parent)){ if(grandparent(node)->right == node->parent->right) grandparent(node)->right = node->parent; else grandparent(node)->left = node->parent; } changeColor(tree, node->parent, BLACK); changeColor(tree, node->parent->left, RED); changeColor(tree, node->parent->right, RED); }