当前位置: 首页>>代码示例>>C++>>正文


C++ rb_color函数代码示例

本文整理汇总了C++中rb_color函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_color函数的具体用法?C++ rb_color怎么用?C++ rb_color使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了rb_color函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: rb_delete_fixup

static void rb_delete_fixup(tree_p tr, tnode_p parent, tnode_p node){
	tnode_p sibling;
	while(node != tr->root && rb_color(node) == BLACK){
		if( node == parent->left ){
			sibling = parent->right;
			if(rb_color(sibling) == RED){
				sibling->color = BLACK;
				parent->color = RED;
				left_rotate(tr, parent);
				sibling = parent->right;
			}

			if(rb_color(sibling->left) == BLACK 
					&& rb_color(sibling->right) == BLACK){
				sibling->color = RED;
				node = parent;
				parent = parent->parent;
			} else if(rb_color(sibling->right) == BLACK){
				sibling->left->color = RED;
				right_rotate(tr, sibling);
				sibling = parent->right;
			} else {
				sibling->color = parent->color;
				parent->color = BLACK;
				sibling->right->color = BLACK;
				left_rotate(tr, parent);
				node = tr->root;
				parent = NULL;
			}
		}
		else{
			sibling = parent->left;
			if(rb_color(sibling) == RED){
				sibling->color = BLACK;
				parent->color = RED;
				right_rotate(tr, parent);
				sibling = parent->left;
			}

			if(rb_color(sibling->left) == BLACK 
					&& rb_color(sibling->right) == BLACK){
				sibling->color = RED;
				node = parent;
				parent = parent->parent;
			} else if(rb_color(sibling->left) == BLACK){
				sibling->right->color = RED;
				left_rotate(tr, sibling);
				sibling = parent->left;
			} else {
				sibling->color = parent->color;
				parent->color = BLACK;
				sibling->left->color = BLACK;
				right_rotate(tr, parent);
				node = tr->root;
				parent = NULL;
			}
		}
	}
	if(node != NULL) node->color = BLACK;
}
开发者ID:Limaa,项目名称:libds,代码行数:60,代码来源:tree.c

示例2: rb_unlink_3

static void rb_unlink_3(struct rb_tree *t, struct rb_node *n,
                        struct rb_callbacks *cb) {
  if (rb_color(n->parent) == RB_BLACK && rb_color(rb_sibling(n)) == RB_BLACK &&
      rb_color(rb_sibling(n)->left) == RB_BLACK &&
      rb_color(rb_sibling(n)->right) == RB_BLACK) {
    rb_sibling(n)->color = RB_RED;
    rb_unlink_1(t, n->parent, cb);
    return;
  }

  rb_unlink_4(t, n, cb);
}
开发者ID:inolen,项目名称:redream,代码行数:12,代码来源:rb_tree.c

示例3: rb_unlink_6

/* There are two cases handled here which are mirror images of one another:
   * N's sibling S is black, S's right child is red, and N is the left child
   of its parent. We exchange the colors of N's parent and sibling, make S's
   right child black, then rotate left at N's parent.
   * N's sibling S is black, S's left child is red, and N is the right child
   of its parent. We exchange the colors of N's parent and sibling, make S's
   left child black, then rotate right at N's parent.

   This accomplishes three things at once:
   * We add a black node to all paths through N, either by adding a black S to
   those paths or by recoloring N's parent black.
   * We remove a black node from all paths through S's red child, either by
   removing P from those paths or by recoloring S.
   * We recolor S's red child black, adding a black node back to all paths
   through S's red child.

   S's left child has become a child of N's parent during the rotation and so
   is unaffected. */
static void rb_unlink_6(struct rb_tree *t, struct rb_node *n,
                        struct rb_callbacks *cb) {
  rb_sibling(n)->color = rb_color(n->parent);
  n->parent->color = RB_BLACK;
  if (n == n->parent->left) {
    CHECK_EQ(rb_color(rb_sibling(n)->right), RB_RED);
    rb_sibling(n)->right->color = RB_BLACK;
    rb_rotate_left(t, n->parent, cb);
  } else {
    CHECK_EQ(rb_color(rb_sibling(n)->left), RB_RED);
    rb_sibling(n)->left->color = RB_BLACK;
    rb_rotate_right(t, n->parent, cb);
  }
}
开发者ID:inolen,项目名称:redream,代码行数:32,代码来源:rb_tree.c

示例4: rb_verify_2

/* Every red node has two children, and both are black (or equivalently, the
   parent of every red node is black). */
static void rb_verify_2(struct rb_node *n) {
  if (!n) {
    return;
  }

  if (rb_color(n) == RB_RED) {
    CHECK_EQ(rb_color(n->left), RB_BLACK);
    CHECK_EQ(rb_color(n->right), RB_BLACK);
    CHECK_EQ(rb_color(n->parent), RB_BLACK);
  }

  rb_verify_2(n->left);
  rb_verify_2(n->right);
}
开发者ID:inolen,项目名称:redream,代码行数:16,代码来源:rb_tree.c

示例5: rb_insert

tnode_p rb_insert(tree_p tr, void * data, int size){
	tnode_p node, current, uncle, parent;

	current = node = tree_insert(tr, data, size);
	node->color = RED;

	while(current != tr->root && rb_color(current->parent) == RED){
		parent = current->parent;
		if(parent == parent->parent->left){
			uncle = parent->parent->right;
			if(rb_color(uncle) == RED){
				parent->color = BLACK;
				uncle->color = BLACK;
				current = parent->parent;
				current->color = RED;
			} else if(current == parent->right){
				current = parent;
				left_rotate(tr, current);
			} else {
				parent->color = BLACK;
				parent->parent->color = RED;
				right_rotate(tr, parent->parent);
			}
		} else {
			uncle = parent->parent->left;
			if(rb_color(uncle) == RED){
				parent->color = BLACK;
				uncle->color = BLACK;
				current = parent->parent;
				current->color = RED;
			} else if(current == parent->left){
				current = parent;
				right_rotate(tr, current);
			} else {
				parent->color = BLACK;
				parent->parent->color = RED;
				left_rotate(tr, parent->parent);
			}
		}
	}

	tr->root->color = BLACK;
	
	return node;
}
开发者ID:Limaa,项目名称:libds,代码行数:45,代码来源:tree.c

示例6: rb_link_2

/* In this case, the new node has a black parent. All the properties are still
   satisfied and we return. */
static void rb_link_2(struct rb_tree *t, struct rb_node *n,
                      struct rb_callbacks *cb) {
  if (rb_color(n->parent) == RB_BLACK) {
    /* tree is still valid */
    return;
  }

  rb_link_3(t, n, cb);
}
开发者ID:inolen,项目名称:redream,代码行数:11,代码来源:rb_tree.c

示例7: _display

void _display(struct rb_node *temp, INFO (*a)[10], int *row, int *col)
{
	if(temp == 0)
		return;
	(*row)++;
	_display(temp->rb_left, a, row,col);
	a[*row][(*col)].color = rb_color(temp);
	a[*row][(*col)++].sid = rb_entry(temp, SAWON,tree)->sid;
	_display(temp->rb_right, a, row, col);
	(*row)--;
}
开发者ID:rumidier,项目名称:Bit,代码行数:11,代码来源:rb_wootree.c

示例8: rb_link_3

static void rb_link_3(struct rb_tree *t, struct rb_node *n,
                      struct rb_callbacks *cb) {
  if (rb_color(rb_uncle(n)) == RB_RED) {
    n->parent->color = RB_BLACK;
    rb_uncle(n)->color = RB_BLACK;
    rb_grandparent(n)->color = RB_RED;
    rb_link_1(t, rb_grandparent(n), cb);
    return;
  }

  rb_link_4(t, n, cb);
}
开发者ID:inolen,项目名称:redream,代码行数:12,代码来源:rb_tree.c

示例9: rb_unlink_2

/* N has a red sibling. In this case we exchange the colors of the parent and
   sibling, then rotate about the parent so that the sibling becomes the
   parent of its former parent. This does not restore the tree properties, but
   reduces the problem to one of the remaining cases. */
static void rb_unlink_2(struct rb_tree *t, struct rb_node *n,
                        struct rb_callbacks *cb) {
  if (rb_color(rb_sibling(n)) == RB_RED) {
    n->parent->color = RB_RED;
    rb_sibling(n)->color = RB_BLACK;
    if (n == n->parent->left) {
      rb_rotate_left(t, n->parent, cb);
    } else {
      rb_rotate_right(t, n->parent, cb);
    }
  }

  rb_unlink_3(t, n, cb);
}
开发者ID:inolen,项目名称:redream,代码行数:18,代码来源:rb_tree.c

示例10: rb_delete

void rb_delete(tree_p tr, tnode_p node){
	tnode_p current = pull_out(tr, node);
	tnode_p next;

	if(current->left != NULL)
		next = current->left;
	else next = current->right;

	if(rb_color(current) == BLACK)
		rb_delete_fixup(tr, current->parent, next);

	current->parent = current->left = current->right = NULL;
	free(current);
}
开发者ID:Limaa,项目名称:libds,代码行数:14,代码来源:tree.c

示例11: rb_verify_3

/* All paths from any given node to its leaf nodes contain the same number of
   black nodes. This one is the trickiest to verify; we do it by traversing
   the tree, incrementing a black node count as we go. The first time we reach
   a leaf we save the count. We return the count so that when we subsequently
   reach other leaves, we compare the count to the saved count. */
static int rb_verify_3(struct rb_node *n, int black_count,
                       int path_black_count) {
  if (rb_color(n) == RB_BLACK) {
    black_count++;
  }

  if (!n) {
    if (path_black_count == -1) {
      path_black_count = black_count;
    } else {
      CHECK_EQ(black_count, path_black_count);
    }
    return path_black_count;
  }

  path_black_count = rb_verify_3(n->left, black_count, path_black_count);
  path_black_count = rb_verify_3(n->right, black_count, path_black_count);

  return path_black_count;
}
开发者ID:inolen,项目名称:redream,代码行数:25,代码来源:rb_tree.c

示例12: rb_unlink

void rb_unlink(struct rb_tree *t, struct rb_node *n, struct rb_callbacks *cb) {
  CHECK(!rb_empty_node(n));

  /* when deleting a node with two non-leaf children, we swap the node with
     its in-order predecessor (the maximum or rightmost element in the left
     subtree), and then delete the original node which now has only one
     non-leaf child */
  if (n->left && n->right) {
    struct rb_node *pred = rb_max(n->left);
    rb_swap_node(t, n, pred);
  }

  /* a node with at most one non-leaf child can simply be replaced with its
     non-leaf child */
  CHECK(!n->left || !n->right);
  struct rb_node *child = n->right ? n->right : n->left;
  if (rb_color(n) == RB_BLACK) {
    rb_unlink_1(t, n, cb);
  }
  rb_replace_node(t, n, child);

  /* force root to black */
  if (t->root) {
    t->root->color = RB_BLACK;
  }

  /* fix up each node in the parent chain */
  if (cb && cb->propagate) {
    cb->propagate(t, n->parent);
  }

  /* clear node state to support rb_empty_node */
  memset(n, 0, sizeof(*n));

#if VERIFY_TREE
  rb_verify(t->root);
#endif
}
开发者ID:inolen,项目名称:redream,代码行数:38,代码来源:rb_tree.c

示例13: rb_unlink_5

/* There are two cases handled here which are mirror images of one another:
   * N's sibling S is black, S's left child is red, S's right child is black,
   and N is the left child of its parent. We exchange the colors of S and its
   left sibling and rotate right at S.
   * N's sibling S is black, S's right child is red, S's left child is black,
   and N is the right child of its parent. We exchange the colors of S and its
   right sibling and rotate left at S.
   Both of these function to reduce us to the situation described in case 6. */
static void rb_unlink_5(struct rb_tree *t, struct rb_node *n,
                        struct rb_callbacks *cb) {
  if (n == n->parent->left && rb_color(rb_sibling(n)) == RB_BLACK &&
      rb_color(rb_sibling(n)->left) == RB_RED &&
      rb_color(rb_sibling(n)->right) == RB_BLACK) {
    rb_sibling(n)->color = RB_RED;
    rb_sibling(n)->left->color = RB_BLACK;
    rb_rotate_right(t, rb_sibling(n), cb);
  } else if (n == n->parent->right && rb_color(rb_sibling(n)) == RB_BLACK &&
             rb_color(rb_sibling(n)->right) == RB_RED &&
             rb_color(rb_sibling(n)->left) == RB_BLACK) {
    rb_sibling(n)->color = RB_RED;
    rb_sibling(n)->right->color = RB_BLACK;
    rb_rotate_left(t, rb_sibling(n), cb);
  }

  rb_unlink_6(t, n, cb);
}
开发者ID:inolen,项目名称:redream,代码行数:26,代码来源:rb_tree.c

示例14: 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);
}
开发者ID:247a,项目名称:lenovo_b6000-8000_kernel_source,代码行数:66,代码来源:rbtree.c

示例15: __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


注:本文中的rb_color函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。