/************************************************************************ Generic insert of a value in the rb tree. @return inserted node */ UNIV_INTERN const ib_rbt_node_t* rbt_insert( /*=======*/ ib_rbt_t* tree, /*!< in: rb tree */ const void* key, /*!< in: key for ordering */ const void* value) /*!< in: value of key, this value is copied to the node */ { ib_rbt_node_t* node; /* Create the node that will hold the value data. */ node = (ib_rbt_node_t*) ut_malloc(SIZEOF_NODE(tree)); memcpy(node->value, value, tree->sizeof_value); node->parent = node->left = node->right = tree->nil; /* Insert in the tree in the usual way. */ rbt_tree_insert(tree, key, node); rbt_balance_tree(tree, node); ++tree->n_nodes; return(node); }
/************************************************************************ Add a new node to the tree, useful for data that is pre-sorted. @return appended node */ UNIV_INTERN const ib_rbt_node_t* rbt_add_node( /*=========*/ ib_rbt_t* tree, /*!< in: rb tree */ ib_rbt_bound_t* parent, /*!< in: bounds */ const void* value) /*!< in: this value is copied to the node */ { ib_rbt_node_t* node; /* Create the node that will hold the value data */ node = (ib_rbt_node_t*) ut_malloc(SIZEOF_NODE(tree)); memcpy(node->value, value, tree->sizeof_value); node->parent = node->left = node->right = tree->nil; /* If tree is empty */ if (parent->last == NULL) { parent->last = tree->root; } /* Append the node, the hope here is that the caller knows what s/he is doing. */ rbt_tree_add_child(tree, parent, node); rbt_balance_tree(tree, node); ++tree->n_nodes; #if defined(IB_RBT_TESTING) ut_a(rbt_validate(tree)); #endif return(node); }
static void BTreeNodeInit (btree_t t, index_t nidx) { node_t n; n = NODE(t,nidx); memset((void *) n, 0, SIZEOF_NODE(MAXCARD_(t))); n->level = -1; }
/**********************************************************************//** Add a new node to the tree, useful for data that is pre-sorted. @return appended node */ UNIV_INTERN const ib_rbt_node_t* rbt_add_node( /*=========*/ ib_rbt_t* tree, /*!< in: rb tree */ ib_rbt_bound_t* parent, /*!< in: bounds */ const void* value) /*!< in: this value is copied to the node */ { ib_rbt_node_t* node; /* Create the node that will hold the value data */ node = (ib_rbt_node_t*) ut_malloc(SIZEOF_NODE(tree)); memcpy(node->value, value, tree->sizeof_value); return(rbt_add_preallocated_node(tree, parent, node)); }