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


C++ ACE_RB_Tree_Node::key方法代码示例

本文整理汇总了C++中ACE_RB_Tree_Node::key方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_RB_Tree_Node::key方法的具体用法?C++ ACE_RB_Tree_Node::key怎么用?C++ ACE_RB_Tree_Node::key使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ACE_RB_Tree_Node的用法示例。


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

示例1: if

template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> ACE_RB_Tree_Node<EXT_ID, INT_ID> *
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::find_node (const EXT_ID &k, ACE_RB_Tree_Base::RB_SearchResult &result)
{
    ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::find_node");

    // Start at the root.
    ACE_RB_Tree_Node<EXT_ID, INT_ID> *current = root_;

    while (current)
    {
        // While there are more nodes to examine.
        if (this->lessthan (current->key (), k))
        {
            // If the search key is greater than the current node's key.
            if (current->right ())
                // If the right subtree is not empty, search to the right.
                current = current->right ();
            else
            {
                // If the right subtree is empty, we're done searching,
                // and are positioned to the left of the insertion point.
                result = LEFT;
                break;
            }
        }
        else if (this->lessthan (k, current->key ()))
        {
            // Else if the search key is less than the current node's key.
            if (current->left ())
                // If the left subtree is not empty, search to the left.
                current = current->left ();
            else
            {
                // If the left subtree is empty, we're done searching,
                // and are positioned to the right of the insertion point.
                result = RIGHT;
                break;
            }
        }
        else
        {
            // If the keys match exactly, we're done as well.
            result = EXACT;
            break;
        }
    }

    return current;
}
开发者ID:imace,项目名称:nnt,代码行数:49,代码来源:RB_Tree.cpp

示例2:

template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK>  int
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::remove_i (ACE_RB_Tree_Node<EXT_ID, INT_ID> *z)
{
  ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::remove_i (ACE_RB_Tree_Node<EXT_ID, INT_ID> *z)");

  // Delete the node and reorganize the tree to satisfy the Red-Black
  // properties.

  ACE_RB_Tree_Node<EXT_ID, INT_ID> *x;
  ACE_RB_Tree_Node<EXT_ID, INT_ID> *y;
  ACE_RB_Tree_Node<EXT_ID, INT_ID> *parent;

  if (z->left () && z->right ())
    y = RB_tree_successor (z);
  else
    y = z;

  if (!y)
    return -1;

  if (y->left ())
    x = y->left ();
  else
    x = y->right ();

  parent = y->parent ();
  if (x)
    {
      x->parent (parent);
    }

  if (parent)
    {
      if (y == parent->left ())
        parent->left (x);
      else
        parent->right (x);
    }
  else
    this->root_ = x;

  if (y != z)
    {
      // Copy the elements of y into z.
      z->key () = y->key ();
      z->item () = y->item ();
    }

  // CLR pp. 263 says that nil nodes are implicitly colored BLACK
  if (!y || y->color () == ACE_RB_Tree_Node_Base::BLACK)
    RB_delete_fixup (x, parent);

  y->parent (0);
  y->right (0);
  y->left (0);
  ACE_DES_FREE_TEMPLATE2 (y,
                          this->allocator_->free,
                          ACE_RB_Tree_Node,
                          EXT_ID, INT_ID);
  --this->current_size_;

  return 0;
}
开发者ID:yuanxu,项目名称:liveshow_r2,代码行数:63,代码来源:RB_Tree.cpp


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