本文整理汇总了C++中rb_set_red函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_set_red函数的具体用法?C++ rb_set_red怎么用?C++ rb_set_red使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rb_set_red函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: rb_insert_color
void rb_insert_color(struct rb_node *node, struct rb_root *root)
{
struct rb_node *parent, *gparent;
while((parent = rb_parent(node)) && rb_is_red(parent)) {
gparent = rb_parent(parent);
if(parent == gparent->rb_left) {
{
register struct rb_node *uncle = gparent->rb_right;
if(uncle && rb_is_red(uncle)) {
rb_set_black(uncle);
rb_set_black(parent);
rb_set_red(gparent);
node = gparent;
continue;
}
}
if(parent->rb_right == node) {
register struct rb_node *tmp;
__rb_rotate_left(parent, root);
tmp = parent;
parent = node;
node = tmp;
}
rb_set_black(parent);
rb_set_red(gparent);
__rb_rotate_right(gparent, root);
} else {
{
register struct rb_node *uncle = gparent->rb_left;
if(uncle && rb_is_red(uncle)) {
rb_set_black(uncle);
rb_set_black(parent);
rb_set_red(gparent);
node = gparent;
continue;
}
}
if(parent->rb_left == node) {
register struct rb_node *tmp;
__rb_rotate_right(parent, root);
tmp = parent;
parent = node;
node = tmp;
}
rb_set_black(parent);
rb_set_red(gparent);
__rb_rotate_left(gparent, root);
}
}
rb_set_black(root->rb_node);
}
开发者ID:dark77777blue,项目名称:src,代码行数:60,代码来源:rbtree.c
示例2: __rb_erase_color
static void __rb_erase_color(LPRB_NODE node, LPRB_NODE parent, LPRB_ROOT root)
{
LPRB_NODE other;
while ((!node || rb_is_black(node)) && node != root->rb_node)
{
if (parent->rb_left == node)
{
other = parent->rb_right;
if (rb_is_red(other))
{
rb_set_black(other);
rb_set_red(parent);
__rb_rotate_left(parent, root);
other = parent->rb_right;
}
if ((!other->rb_left || rb_is_black(other->rb_left)) &&
(!other->rb_right || rb_is_black(other->rb_right)))
{
rb_set_red(other);
node = parent;
parent = rb_parent(node);
}
else
{
if (!other->rb_right || rb_is_black(other->rb_right))
{
rb_set_black(other->rb_left);
rb_set_red(other);
__rb_rotate_right(other, root);
other = parent->rb_right;
}
rb_set_color(other, rb_color(parent));
rb_set_black(parent);
rb_set_black(other->rb_right);
__rb_rotate_left(parent, root);
node = root->rb_node;
break;
}
}
else
{
other = parent->rb_left;
if (rb_is_red(other))
{
rb_set_black(other);
rb_set_red(parent);
__rb_rotate_right(parent, root);
other = parent->rb_left;
}
if ((!other->rb_left || rb_is_black(other->rb_left)) &&
(!other->rb_right || rb_is_black(other->rb_right)))
{
rb_set_red(other);
node = parent;
parent = rb_parent(node);
}
else
{
if (!other->rb_left || rb_is_black(other->rb_left))
{
rb_set_black(other->rb_right);
rb_set_red(other);
__rb_rotate_left(other, root);
other = parent->rb_left;
}
rb_set_color(other, rb_color(parent));
rb_set_black(parent);
rb_set_black(other->rb_left);
__rb_rotate_right(parent, root);
node = root->rb_node;
break;
}
}
}
if (node)
rb_set_black(node);
}
开发者ID:MirShu,项目名称:ArcFace,代码行数:78,代码来源:rbtree.c
示例3: rb_insert_color
void rb_insert_color(LPRB_NODE node, LPRB_ROOT root)
{
LPRB_NODE parent, gparent;
while ((parent = rb_parent(node)) && rb_is_red(parent))
{
gparent = rb_parent(parent);
if (parent == gparent->rb_left)
{
{
register LPRB_NODE uncle = gparent->rb_right;
if (uncle && rb_is_red(uncle))
{
rb_set_black(uncle);
rb_set_black(parent);
rb_set_red(gparent);
node = gparent;
continue;
}
}
if (parent->rb_right == node)
{
register LPRB_NODE tmp;
__rb_rotate_left(parent, root);
tmp = parent;
parent = node;
node = tmp;
}
rb_set_black(parent);
rb_set_red(gparent);
__rb_rotate_right(gparent, root);
} else {
{
register LPRB_NODE uncle = gparent->rb_left;
if (uncle && rb_is_red(uncle))
{
rb_set_black(uncle);
rb_set_black(parent);
rb_set_red(gparent);
node = gparent;
continue;
}
}
if (parent->rb_left == node)
{
register LPRB_NODE tmp;
__rb_rotate_right(parent, root);
tmp = parent;
parent = node;
node = tmp;
}
rb_set_black(parent);
rb_set_red(gparent);
__rb_rotate_left(gparent, root);
}
}
rb_set_black(root->rb_node);
}
开发者ID:MirShu,项目名称:ArcFace,代码行数:64,代码来源:rbtree.c
示例4: __rb_erase_color
static void __rb_erase_color(struct rb_node *node, struct rb_node *parent,
struct rb_root *root)
{
struct rb_node *other;
while ((!node || rb_is_black(node)) && node != root->rb_node)
{
if (parent->rb_left == node)
{
other = parent->rb_right;
if (rb_is_red(other))
{
rb_set_black(other);
rb_set_red(parent);
__rb_rotate_left(parent, root);
other = parent->rb_right;
}
if ((!other->rb_left || rb_is_black(other->rb_left)) &&
(!other->rb_right || rb_is_black(other->rb_right)))
{
rb_set_red(other);
node = parent;
parent = rb_parent(node);
}
else
{
if (!other->rb_right || rb_is_black(other->rb_right))
{
struct rb_node *o_left;
if ((o_left = other->rb_left))
rb_set_black(o_left);
rb_set_red(other);
__rb_rotate_right(other, root);
other = parent->rb_right;
}
rb_set_color(other, rb_color(parent));
rb_set_black(parent);
if (other->rb_right)
rb_set_black(other->rb_right);
__rb_rotate_left(parent, root);
node = root->rb_node;
break;
}
}
else
{
other = parent->rb_left;
if (rb_is_red(other))
{
rb_set_black(other);
rb_set_red(parent);
__rb_rotate_right(parent, root);
other = parent->rb_left;
}
if ((!other->rb_left || rb_is_black(other->rb_left)) &&
(!other->rb_right || rb_is_black(other->rb_right)))
{
rb_set_red(other);
node = parent;
parent = rb_parent(node);
}
else
{
if (!other->rb_left || rb_is_black(other->rb_left))
{
register struct rb_node *o_right;
if ((o_right = other->rb_right))
rb_set_black(o_right);
rb_set_red(other);
__rb_rotate_left(other, root);
other = parent->rb_left;
}
rb_set_color(other, rb_color(parent));
rb_set_black(parent);
if (other->rb_left)
rb_set_black(other->rb_left);
__rb_rotate_right(parent, root);
node = root->rb_node;
break;
}
}
}
if (node)
rb_set_black(node);
}
开发者ID:247a,项目名称:lenovo_b6000-8000_kernel_source,代码行数:85,代码来源:rbtree.c
示例5: rb_insert_color
void rb_insert_color(struct rb_node *node, struct rb_root *root)
{
struct rb_node *parent, *gparent;
struct mytype *mytype;
int pr_flag = 1;
mytype = container_of(node, struct mytype, node);
while ((parent = rb_parent(node)) && rb_is_red(parent))
{
gparent = rb_parent(parent);
if (parent == gparent->rb_left)
{
{
register struct rb_node *uncle = gparent->rb_right;
if (uncle && rb_is_red(uncle))
{
if (pr_flag)
{
pr_debug("insert value = %02d, 对应情况1。\n", mytype->keyvalue);
pr_flag = 0;
}
rb_set_black(uncle);
rb_set_black(parent);
rb_set_red(gparent);
node = gparent;
continue;
}
}
if (parent->rb_right == node)
{
if (pr_flag)
{
pr_debug("insert value = %02d, 对应情况2。\n", mytype->keyvalue);
pr_flag = 0;
}
register struct rb_node *tmp;
__rb_rotate_left(parent, root);
tmp = parent;
parent = node;
node = tmp;
}
if (pr_flag)
{
pr_debug("insert value = %02d, 对应情况3。\n", mytype->keyvalue);
pr_flag = 0;
}
rb_set_black(parent);
rb_set_red(gparent);
__rb_rotate_right(gparent, root);
} else {
{
register struct rb_node *uncle = gparent->rb_left;
if (uncle && rb_is_red(uncle))
{
if (pr_flag)
{
pr_debug("insert value = %02d, 对应情况1(反)。\n", mytype->keyvalue);
pr_flag = 0;
}
rb_set_black(uncle);
rb_set_black(parent);
rb_set_red(gparent);
node = gparent;
continue;
}
}
if (parent->rb_left == node)
{
if (pr_flag)
{
pr_debug("insert value = %02d, 对应情况2(反)。\n", mytype->keyvalue);
pr_flag = 0;
}
register struct rb_node *tmp;
__rb_rotate_right(parent, root);
tmp = parent;
parent = node;
node = tmp;
}
if (pr_flag)
{
pr_debug("insert value = %02d, 对应情况3(反)。\n", mytype->keyvalue);
pr_flag = 0;
}
rb_set_black(parent);
//.........这里部分代码省略.........
开发者ID:TihsYloH,项目名称:smart_server,代码行数:101,代码来源:rbtree.c
示例6: __rb_erase_color
static void __rb_erase_color(struct rb_node *node, struct rb_node *parent,
struct rb_root *root)
{
struct rb_node *other;
int pr_flag = 1;
while ((!node || rb_is_black(node)) && node != root->rb_node)
{
if (parent->rb_left == node)
{
other = parent->rb_right;
if (rb_is_red(other))
{
if (pr_flag)
{
pr_debug("对应情况1。\n");
pr_flag = 0;
}
rb_set_black(other);
rb_set_red(parent);
__rb_rotate_left(parent, root);
other = parent->rb_right;
}
if ((!other->rb_left || rb_is_black(other->rb_left)) &&
(!other->rb_right || rb_is_black(other->rb_right)))
{
if (pr_flag)
{
pr_debug("对应情况2。\n");
pr_flag = 0;
}
rb_set_red(other);
node = parent;
parent = rb_parent(node);
}
else
{
if (!other->rb_right || rb_is_black(other->rb_right))
{
if (pr_flag)
{
pr_debug("对应情况3。\n");
pr_flag = 0;
}
rb_set_black(other->rb_left);
rb_set_red(other);
__rb_rotate_right(other, root);
other = parent->rb_right;
}
if (pr_flag)
{
pr_debug("对应情况4。\n");
pr_flag = 0;
}
rb_set_color(other, rb_color(parent));
rb_set_black(parent);
rb_set_black(other->rb_right);
__rb_rotate_left(parent, root);
node = root->rb_node;
break;
}
}
else
{
other = parent->rb_left;
if (rb_is_red(other))
{
if (pr_flag)
{
pr_debug("对应情况1(反)。\n");
pr_flag = 0;
}
rb_set_black(other);
rb_set_red(parent);
__rb_rotate_right(parent, root);
other = parent->rb_left;
}
if ((!other->rb_left || rb_is_black(other->rb_left)) &&
(!other->rb_right || rb_is_black(other->rb_right)))
{
if (pr_flag)
{
pr_debug("对应情况2(反)。\n");
pr_flag = 0;
}
rb_set_red(other);
node = parent;
parent = rb_parent(node);
}
else
{
if (!other->rb_left || rb_is_black(other->rb_left))
//.........这里部分代码省略.........
开发者ID:TihsYloH,项目名称:smart_server,代码行数:101,代码来源:rbtree.c
示例7: rb_insert_rebalance
void rb_insert_rebalance(struct rb_node* node, struct rb_root* root)
{
struct rb_node *parent, *gparent, *uncle;
while ((parent = rb_parent(node)) && rb_is_red(parent)) {
gparent = rb_parent(parent);
if (parent == gparent->left) {
uncle = gparent->right;
if (uncle && rb_is_red(uncle)) {
rb_set_black(uncle);
rb_set_black(parent);
rb_set_red(gparent);
node = gparent;
continue;
}
if (node == parent->right) {
register struct rb_node* tmp;
rb_rotate_left(parent, root);
tmp = node;
node = parent;
parent = tmp;
}
rb_rotate_right(gparent, root);
rb_set_black(parent);
rb_set_red(gparent);
continue;
}
uncle = gparent->left;
if (uncle && rb_is_red(uncle)) {
rb_set_black(parent);
rb_set_black(uncle);
rb_set_red(gparent);
node = gparent;
continue;
}
if (node == parent->left) {
register struct rb_node* tmp;
rb_rotate_right(parent, root);
tmp = node;
node = parent;
parent = tmp;
}
rb_rotate_left(gparent, root);
rb_set_red(gparent);
rb_set_black(parent);
}
rb_set_black(root->node);
}
开发者ID:songhowl,项目名称:devkit,代码行数:61,代码来源:rbtree.c
示例8: rb_delete_rebalance
static inline void rb_delete_rebalance(struct rb_node* node,
struct rb_node* parent,
struct rb_root* root)
{
struct rb_node* sibling;
while ((!node || rb_is_black(node)) && (node != root->node)) {
if (node == parent->left) {
sibling = parent->right;
if (rb_is_red(sibling)) {
rb_rotate_left(parent, root);
rb_set_red(parent);
rb_set_black(sibling);
sibling = parent->right;
}
if ((!sibling->left || rb_is_black(sibling->left)) &&
(!sibling->right || rb_is_black(sibling->right))) {
rb_set_red(sibling);
node = parent;
/* if (node) */ parent = rb_parent(node);
} else {
if (!sibling->right || rb_is_black(sibling->right)) {
rb_set_black(sibling->left);
rb_set_red(sibling);
rb_rotate_right(sibling, root);
sibling = parent->right;
}
rb_set_color(sibling, rb_color(parent));
rb_set_black(parent);
rb_set_black(sibling->right);
rb_rotate_left(parent, root);
node = root->node;
break;
}
} else {
sibling = parent->left;
if (rb_is_red(sibling)) {
rb_rotate_right(parent, root);
rb_set_red(parent);
rb_set_black(sibling);
sibling = parent->left;
}
if ((!sibling->left || rb_is_black(sibling->left)) &&
(!sibling->right || rb_is_black(sibling->right))) {
rb_set_red(sibling);
node = parent;
/* if (node) */ parent = rb_parent(node);
} else {
if (!sibling->left || rb_is_black(sibling->left)) {
rb_set_black(sibling->right);
rb_set_red(sibling);
rb_rotate_left(sibling, root);
sibling = parent->left;
}
rb_set_color(sibling, rb_color(parent));
rb_set_black(parent);
rb_set_black(sibling->left);
rb_rotate_right(parent, root);
node = root->node;
break;
}
}
}
if (node)
rb_set_black(node);
}
开发者ID:songhowl,项目名称:devkit,代码行数:75,代码来源:rbtree.c
示例9: rbtree_delete_fixup
/*
* 红黑树删除修正函数
*
* 在从红黑树中删除插入节点之后(红黑树失去平衡),再调用该函数;
* 目的是将它重新塑造成一颗红黑树。
*
* 参数说明:
* root 红黑树的根
* node 待修正的节点
*/
static void rbtree_delete_fixup(RBRoot *root, Node *node, Node *parent)
{
Node *other;
while ((!node || rb_is_black(node)) && node != root->node)
{
if (parent->left == node)
{
//1. parent parent.r old.ohter.b
// / \ / \ / \
// child.b other.r child.b other.b parent.r d
// / \ / \ / \ / \ / \
// a b c d a b c d child.b c <- new.other
// / \
// a b
other = parent->right;
if (rb_is_red(other))
{
// Case 1: x的兄弟w是红色的
rb_set_black(other);
rb_set_red(parent);
rbtree_left_rotate(root, parent);
other = parent->right;
}
//2. gparent gparent 3. <- new.parent
// |
// parent parent 2. <- new.child
// / \ / \
// child.b other old.child.b other.r 1. <- color = RED
// / \ / \
// a b c.b d.b
if ((!other->left || rb_is_black(other->left)) &&
(!other->right || rb_is_black(other->right)))
{
// Case 2: x的兄弟w是黑色,且w的俩个孩子也都是黑色的
rb_set_red(other);
node = parent;
parent = rb_parent(node);
}
else
{
if (!other->right || rb_is_black(other->right))
{
//3.1 parent parent parent
// / \ / \ / \
// child.b other.b child.b other.r <- color RED child.b c.b <- new.other
// / \ / \ / \ / \ / \ \
// a b c d.b a b c.b d.b <- c.color BLACK a b old.other.r
// / \
// d.b
// Case 3: x的兄弟w是黑色的,并且w的左孩子是红色,右孩子为黑色。
rb_set_black(other->left);
rb_set_red(other);
rbtree_right_rotate(root, other);
other = parent->right;
}
//3.2 parent.c parent.b 2<- color BLACK other.b
// / \ / \ / \
// child.b other.b child.b other.c 1<- color parent.color parent.b d.b
// / \ / \ / \ / \ / \
// a b c d.r a b c d.b 3<- color BLACK child.b c
// / \
// a b
// Case 4: x的兄弟w是黑色的;并且w的右孩子是红色的,左孩子任意颜色。
rb_set_color(other, rb_color(parent));
rb_set_black(parent);
rb_set_black(other->right);
rbtree_left_rotate(root, parent);
node = root->node;
break;
}
}
else
{
other = parent->left;
if (rb_is_red(other))
{
// Case 1: x的兄弟w是红色的
rb_set_black(other);
rb_set_red(parent);
rbtree_right_rotate(root, parent);
other = parent->left;
}
if ((!other->left || rb_is_black(other->left)) &&
(!other->right || rb_is_black(other->right)))
{
// Case 2: x的兄弟w是黑色,且w的俩个孩子也都是黑色的
rb_set_red(other);
node = parent;
//.........这里部分代码省略.........
开发者ID:bycool,项目名称:programming,代码行数:101,代码来源:rbtree.c
示例10: rbtree_insert_fixup
/*
* 红黑树插入修正函数
*
* 在向红黑树中插入节点之后(失去平衡),再调用该函数;
* 目的是将它重新塑造成一颗红黑树。
*
* 参数说明:
* root 红黑树的根
* node 插入的结点 // 对应《算法导论》中的z
*/
static void rbtree_insert_fixup(RBRoot *root, Node *node)
{
Node *parent, *gparent;
// 若“父节点存在,并且父节点的颜色是红色”
while ((parent = rb_parent(node)) && rb_is_red(parent))
{
gparent = rb_parent(parent);
//若“父节点”是“祖父节点的左孩子”
if (parent == gparent->left)
{
// Case 1条件:叔叔节点是红色
{
Node *uncle = gparent->right;
if (uncle && rb_is_red(uncle))
{
rb_set_black(uncle);
rb_set_black(parent);
rb_set_red(gparent);
node = gparent;
continue;
}
}
// Case 2条件:叔叔是黑色,且当前节点是右孩子
if (parent->right == node)
{
Node *tmp;
rbtree_left_rotate(root, parent);
tmp = parent;
parent = node;
node = tmp;
}
// Case 3条件:叔叔是黑色,且当前节点是左孩子。
rb_set_black(parent);
rb_set_red(gparent);
rbtree_right_rotate(root, gparent);
}
else//若“z的父节点”是“z的祖父节点的右孩子”
{
// Case 1条件:叔叔节点是红色
{
Node *uncle = gparent->left;
if (uncle && rb_is_red(uncle))
{
rb_set_black(uncle);
rb_set_black(parent);
rb_set_red(gparent);
node = gparent;
continue;
}
}
// Case 2条件:叔叔是黑色,且当前节点是左孩子
if (parent->left == node)
{
Node *tmp;
rbtree_right_rotate(root, parent);
tmp = parent;
parent = node;
node = tmp;
}
// Case 3条件:叔叔是黑色,且当前节点是右孩子。
rb_set_black(parent);
rb_set_red(gparent);
rbtree_left_rotate(root, gparent);
}
}
// 将根节点设为黑色
rb_set_black(root->node);
}
开发者ID:bycool,项目名称:programming,代码行数:85,代码来源:rbtree.c
注:本文中的rb_set_red函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论