本文整理汇总了C++中rb_set_parent函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_set_parent函数的具体用法?C++ rb_set_parent怎么用?C++ rb_set_parent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rb_set_parent函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: __rb_rotate_right
static void __rb_rotate_right(struct rb_node *node, struct rb_root *root)
{
struct rb_node *left = node->rb_left;
struct rb_node *parent = rb_parent(node);
if((node->rb_left = left->rb_right)) {
rb_set_parent(left->rb_right, node);
}
left->rb_right = node;
rb_set_parent(left, parent);
if(parent) {
if(node == parent->rb_right) {
parent->rb_right = left;
} else {
parent->rb_left = left;
}
} else {
root->rb_node = left;
}
rb_set_parent(node, left);
}
示例2: rb_rotate_right
static void rb_rotate_right(struct rb_node* x, struct rb_root* root)
{
struct rb_node *y = x->left, *px = rb_parent(x);
x->left = y->right;
rb_set_parent(y, px);
if (y->right)
rb_set_parent(y->right, x);
if (px) {
if (x == px->left)
px->left = y;
else
px->right = y;
} else
root->node = y;
y->right = x;
rb_set_parent(x, y);
}
示例3: __rb_rotate_right
static void __rb_rotate_right(struct rb_node *node, struct rb_root *root)
{
struct rb_node *left = node->rb_left;
struct rb_node *parent = rb_parent(node);
node->rb_left = left->rb_right;
if (node->rb_left)
rb_set_parent(left->rb_right, node);
left->rb_right = node;
rb_set_parent(left, parent);
if (parent) {
if (node == parent->rb_right)
parent->rb_right = left;
else
parent->rb_left = left;
} else
root->rb_node = left;
rb_set_parent(node, left);
}
示例4: rb_rotate_right
static void rb_rotate_right(char *node, char **tree)
{
char *p = node;
char *q = rbtree_get_left(node); /* can't be NULL */
char *parent = rb_get_parent(p);
if (!rb_is_root(p)) {
if (rbtree_get_left(parent) == p)
rb_set_left(q, parent);
else
rb_set_right(q, parent);
} else
*tree = q;
rb_set_parent(parent, q);
rb_set_parent(q, p);
rb_set_left(rbtree_get_right(q), p);
if (rbtree_get_left(p))
rb_set_parent(p, rbtree_get_left(p));
rb_set_right(p, q);
}
示例5: __rb_rotate_left
static void __rb_rotate_left(struct rb_node *node, struct rb_root *root)
{
struct rb_node *right = node->rb_right;
struct rb_node *parent = rb_parent(node);
if ((node->rb_right = right->rb_left))
rb_set_parent(right->rb_left, node);
right->rb_left = node;
rb_set_parent(right, parent);
if (parent) {
if (node == parent->rb_left)
parent->rb_left = right;
else
parent->rb_right = right;
}
else
root->rb_node = right;
rb_set_parent(node, right);
}
示例6: __rb_rotate_right
static void __rb_rotate_right(LPRB_NODE node, LPRB_ROOT root)
{
LPRB_NODE left = node->rb_left;
LPRB_NODE parent = rb_parent(node);
if ((node->rb_left = left->rb_right))
rb_set_parent(left->rb_right, node);
left->rb_right = node;
rb_set_parent(left, parent);
if (parent)
{
if (node == parent->rb_right)
parent->rb_right = left;
else
parent->rb_left = left;
}
else
root->rb_node = left;
rb_set_parent(node, left);
}
示例7: rb_replace_node
void rb_replace_node(struct rb_node *victim, struct rb_node *new_node,
struct rb_root *root)
{
struct rb_node *parent = rb_parent(victim);
/* Set the surrounding nodes to point to the replacement */
if (parent) {
if (victim == parent->rb_left)
parent->rb_left = new_node;
else
parent->rb_right = new_node;
} else {
root->rb_node = new_node;
}
if (victim->rb_left)
rb_set_parent(victim->rb_left, new_node);
if (victim->rb_right)
rb_set_parent(victim->rb_right, new_node);
/* Copy the pointers/colour from the victim to the replacement */
*new_node = *victim;
}
示例8: rb_erase
void rb_erase(LPRB_NODE node, LPRB_ROOT root)
{
LPRB_NODE child, parent;
int color;
if (!node->rb_left)
child = node->rb_right;
else if (!node->rb_right)
child = node->rb_left;
else
{
LPRB_NODE old = node, left;
node = node->rb_right;
while ((left = node->rb_left) != NULL)
node = left;
if (rb_parent(old)) {
if (rb_parent(old)->rb_left == old)
rb_parent(old)->rb_left = node;
else
rb_parent(old)->rb_right = node;
} else
root->rb_node = node;
child = node->rb_right;
parent = rb_parent(node);
color = rb_color(node);
if (parent == old) {
parent = node;
} else {
if (child)
rb_set_parent(child, parent);
parent->rb_left = child;
node->rb_right = old->rb_right;
rb_set_parent(old->rb_right, node);
}
node->rb_parent_color = old->rb_parent_color;
node->rb_left = old->rb_left;
rb_set_parent(old->rb_left, node);
goto color;
}
parent = rb_parent(node);
color = rb_color(node);
if (child)
rb_set_parent(child, parent);
if (parent)
{
if (parent->rb_left == node)
parent->rb_left = child;
else
parent->rb_right = child;
}
else
root->rb_node = child;
color:
if (color == RB_BLACK)
__rb_erase_color(child, parent, root);
}
示例9: rb_erase
void rb_erase(struct rb_node *node, struct rb_root *root)
{
struct rb_node *child, *parent;
int color;
if (!node->rb_left)
child = node->rb_right;
else if (!node->rb_right)
child = node->rb_left;
else
{
struct rb_node *old = node, *left;
node = node->rb_right;
while ((left = node->rb_left) != NULL)
node = left;
child = node->rb_right;
parent = rb_parent(node);
color = rb_color(node);
if (child)
rb_set_parent(child, parent);
if (parent == old) {
parent->rb_right = child;
parent = node;
} else
parent->rb_left = child;
node->rb_parent_color = old->rb_parent_color;
node->rb_right = old->rb_right;
node->rb_left = old->rb_left;
if (rb_parent(old))
{
if (rb_parent(old)->rb_left == old)
rb_parent(old)->rb_left = node;
else
rb_parent(old)->rb_right = node;
} else
root->rb_node = node;
rb_set_parent(old->rb_left, node);
if (old->rb_right)
rb_set_parent(old->rb_right, node);
goto color;
}
parent = rb_parent(node);
color = rb_color(node);
if (child)
rb_set_parent(child, parent);
if (parent)
{
if (parent->rb_left == node)
parent->rb_left = child;
else
parent->rb_right = child;
}
else
root->rb_node = child;
color:
if (color == RB_BLACK)
__rb_erase_color(child, parent, root);
}
示例10: rb_erase
void rb_erase(struct rb_node *node, struct rb_root *root)
{
struct rb_node *child, *parent;
int color;
struct mytype *mytype;
mytype = container_of(node, struct mytype, node);
if (!node->rb_left)
child = node->rb_right;
else if (!node->rb_right)
child = node->rb_left;
else
{
struct rb_node *old = node, *left;
node = node->rb_right;
while ((left = node->rb_left) != NULL)
node = left;
if (rb_parent(old)) {
if (rb_parent(old)->rb_left == old)
rb_parent(old)->rb_left = node;
else
rb_parent(old)->rb_right = node;
} else
root->rb_node = node;
child = node->rb_right;
parent = rb_parent(node);
color = rb_color(node);
if (parent == old) {
parent = node;
} else {
if (child)
rb_set_parent(child, parent);
parent->rb_left = child;
node->rb_right = old->rb_right;
rb_set_parent(old->rb_right, node);
}
node->rb_parent_color = old->rb_parent_color;
node->rb_left = old->rb_left;
rb_set_parent(old->rb_left, node);
goto color;
}
parent = rb_parent(node);
color = rb_color(node);
if (child)
rb_set_parent(child, parent);
if (parent)
{
if (parent->rb_left == node)
parent->rb_left = child;
else
parent->rb_right = child;
}
else
root->rb_node = child;
color:
if (color == RB_BLACK)
{
pr_debug("delete value = %02d, ", mytype->keyvalue);
__rb_erase_color(child, parent, root);
}
else
{
pr_debug("delete value = %02d, 对应情况X。\n", mytype->keyvalue);
}
}
示例11: rbtree_remove
static void rbtree_remove(char *node, char **tree)
{
char *parent = rb_get_parent(node);
char *left = rbtree_get_left(node);
char *right = rbtree_get_right(node);
char *next;
int color;
if (!left)
next = right;
else if (!right)
next = left;
else
next = rbtree_first(right);
if (parent)
rb_set_child(next, parent, rbtree_get_left(parent) == node);
else
*tree = next;
if (left && right) {
color = rb_get_color(next);
rb_set_color(rb_get_color(node), next);
rb_set_left(left, next);
rb_set_parent(next, left);
if (next != right) {
parent = rb_get_parent(next);
rb_set_parent(rb_get_parent(node), next);
node = rbtree_get_right(next);
rb_set_left(node, parent);
rb_set_right(right, next);
rb_set_parent(next, right);
} else {
rb_set_parent(parent, next);
parent = next;
node = rbtree_get_right(next);
}
} else {
color = rb_get_color(node);
node = next;
}
/*
* 'node' is now the sole successor's child and 'parent' its
* new parent (since the successor can have been moved).
*/
if (node)
rb_set_parent(parent, node);
/*
* The 'easy' cases.
*/
if (color == RB_RED)
return;
if (node && rb_is_red(node)) {
rb_set_color(RB_BLACK, node);
return;
}
do {
if (node == *tree)
break;
if (node == rbtree_get_left(parent)) {
char *sibling = rbtree_get_right(parent);
if (rb_is_red(sibling)) {
rb_set_color(RB_BLACK, sibling);
rb_set_color(RB_RED, parent);
rb_rotate_left(parent, tree);
sibling = rbtree_get_right(parent);
}
if ((!rbtree_get_left(sibling) || rb_is_black(rbtree_get_left(sibling))) &&
(!rbtree_get_right(sibling) || rb_is_black(rbtree_get_right(sibling)))) {
rb_set_color(RB_RED, sibling);
node = parent;
parent = rb_get_parent(parent);
continue;
}
if (!rbtree_get_right(sibling) || rb_is_black(rbtree_get_right(sibling))) {
rb_set_color(RB_BLACK, rbtree_get_left(sibling));
rb_set_color(RB_RED, sibling);
rb_rotate_right(sibling, tree);
sibling = rbtree_get_right(parent);
}
rb_set_color(rb_get_color(parent), sibling);
rb_set_color(RB_BLACK, parent);
rb_set_color(RB_BLACK, rbtree_get_right(sibling));
rb_rotate_left(parent, tree);
node = *tree;
break;
} else {
char *sibling = rbtree_get_left(parent);
if (rb_is_red(sibling)) {
rb_set_color(RB_BLACK, sibling);
rb_set_color(RB_RED, parent);
//.........这里部分代码省略.........
示例12: rb_do_lookup
static char *rbtree_insert(char *node, char **tree)
{
char *key, *parent;
int is_left;
key = rb_do_lookup(node, *tree, &parent, &is_left);
if (key)
return key;
rb_set_left(NULL, node);
rb_set_right(NULL, node);
rb_set_color(RB_RED, node);
rb_set_parent(parent, node);
if (parent) {
rb_set_child(node, parent, is_left);
} else {
*tree = node;
}
/*
* Fixup the modified tree by recoloring nodes and performing
* rotations (2 at most) hence the red-black tree properties are
* preserved.
*/
while ((parent = rb_get_parent(node)) && rb_is_red(parent)) {
char *grandpa = rb_get_parent(parent);
if (parent == rbtree_get_left(grandpa)) {
char *uncle = rbtree_get_right(grandpa);
if (uncle && rb_is_red(uncle)) {
rb_set_color(RB_BLACK, parent);
rb_set_color(RB_BLACK, uncle);
rb_set_color(RB_RED, grandpa);
node = grandpa;
} else {
if (node == rbtree_get_right(parent)) {
rb_rotate_left(parent, tree);
node = parent;
parent = rb_get_parent(node);
}
rb_set_color(RB_BLACK, parent);
rb_set_color(RB_RED, grandpa);
rb_rotate_right(grandpa, tree);
}
} else {
char *uncle = rbtree_get_left(grandpa);
if (uncle && rb_is_red(uncle)) {
rb_set_color(RB_BLACK, parent);
rb_set_color(RB_BLACK, uncle);
rb_set_color(RB_RED, grandpa);
node = grandpa;
} else {
if (node == rbtree_get_left(parent)) {
rb_rotate_right(parent, tree);
node = parent;
parent = rb_get_parent(node);
}
rb_set_color(RB_BLACK, parent);
rb_set_color(RB_RED, grandpa);
rb_rotate_left(grandpa, tree);
}
}
}
rb_set_color(RB_BLACK, *tree);
return NULL;
}
示例13: rb_delete
void rb_delete(struct rb_node* node, struct rb_root* root)
{
int color;
struct rb_node *parent, *child = NULL;
if (node->left && node->right) {
struct rb_node* old = node;
struct rb_node* old_parent = rb_parent(node);
node = node->right;
while (node->left)
node = node->left;
if (old_parent) {
if (old == old_parent->left)
old_parent->left = node;
else
old_parent->right = node;
} else
root->node = node;
child = node->right;
parent = rb_parent(node);
color = rb_color(node);
if (parent == old)
parent = node;
else {
if (child)
rb_set_parent(child, parent);
parent->left = child;
node->right = old->right;
rb_set_parent(old->right, node);
}
node->parent_color = old->parent_color;
node->left = old->left;
rb_set_parent(old->left, node);
goto rebalance;
}
if (!node->left)
child = node->right;
else
child = node->left;
parent = rb_parent(node);
color = rb_color(node);
if (child)
rb_set_parent(child, parent);
if (parent) {
if (node == parent->left)
parent->left = child;
else
parent->right = child;
} else
root->node = child;
rebalance:
if (color == RB_BLACK)
rb_delete_rebalance(child, parent, root);
}
示例14: rbtree_delete
/*
* 删除结点
*
* 参数说明:
* tree 红黑树的根结点
* node 删除的结点
*/
void rbtree_delete(RBRoot *root, Node *node)
{
Node *child, *parent;
int color;
// tree
// / \
// dnode
// / \
// left right
// / \
// replace right
// 被删除节点的"左右孩子都不为空"的情况。
if ( (node->left!=NULL) && (node->right!=NULL) )
{
// 被删节点的后继节点。(称为"取代节点")
// 用它来取代"被删节点"的位置,然后再将"被删节点"去掉。
Node *replace = node;
// 获取后继节点
replace = replace->right;
while (replace->left != NULL)
replace = replace->left;
// "node节点"不是根节点(只有根节点不存在父节点)
if (rb_parent(node))
{
if (rb_parent(node)->left == node)
rb_parent(node)->left = replace;
else
rb_parent(node)->right = replace;
}
else
// "node节点"是根节点,更新根节点。
root->node = replace;
// child是"取代节点"的右孩子,也是需要"调整的节点"。
// "取代节点"肯定不存在左孩子!因为它是一个后继节点。
child = replace->right;
parent = rb_parent(replace);
// 保存"取代节点"的颜色
color = rb_color(replace);
// "被删除节点"是"它的后继节点的父节点"
if (parent == node)
{
parent = replace;
}
else
{
// child不为空
if (child)
rb_set_parent(child, parent);
parent->left = child;
replace->right = node->right;
rb_set_parent(node->right, replace);
}
replace->parent = node->parent;
replace->color = node->color;
replace->left = node->left;
node->left->parent = replace;
if (color == BLACK)
rbtree_delete_fixup(root, child, parent);
free(node);
return ;
}
if (node->left !=NULL)
child = node->left;
else
child = node->right;
parent = node->parent;
// 保存"取代节点"的颜色
color = node->color;
if (child)
child->parent = parent;
// "node节点"不是根节点
if (parent)
{
if (parent->left == node)
parent->left = child;
else
parent->right = child;
}
else
//.........这里部分代码省略.........