Exemplo n.º 1
0
static void rbt_delete_node(rbt_t* tree, rbt_node_t* node){
    rbt_node_t* descendant = NULL;
    if(node->left && node->right){
        descendant = rightmost_descendant(node->left);
        mem_retain(descendant);
        rbt_delete_node(tree, descendant);
        if(node->left) node->left->parent = descendant;
        if(node->right) node->right->parent = descendant;
        descendant->left = node->left;
        descendant->right = node->right;
        descendant->color = node->color;
    }else if(BLACK == rbt_node_color(node)){
        //black node with at most one non-leaf child
        if(RED == rbt_node_color(node->left) || RED == rbt_node_color(node->right)){
            descendant = node->left ? node->left : node->right;
            descendant->color = BLACK;
        } else {
            rbt_del_rebalance(tree, node);
        }
    }
    rbt_node_replace(tree, node, descendant);
    node->left = NULL;
    node->right = NULL;
    node->parent = NULL;
    mem_release(node);
}
      void
      dec(true_type)
      {
	if (m_p_nd->m_type == pat_trie_head_node_type)
	  {
	    m_p_nd = static_cast<head_pointer>(m_p_nd)->m_p_max;
	    return;
	  }

	node_pointer p_y = m_p_nd->m_p_parent;
	while (p_y->m_type != pat_trie_head_node_type && 
	       get_smaller_sibling(m_p_nd) == 0)
	  {
	    m_p_nd = p_y;
	    p_y = p_y->m_p_parent;
	  }

	if (p_y->m_type == pat_trie_head_node_type)
	  {
	    m_p_nd = p_y;
	    return;
	  }
	m_p_nd = rightmost_descendant(get_smaller_sibling(m_p_nd));
      }
Exemplo n.º 3
0
static rbt_node_t* rightmost_descendant(rbt_node_t* node){
    return (node->right) ? rightmost_descendant(node->right) : node;
}