Ejemplo n.º 1
0
/************************************************************************
Recursively free the nodes. */
static
void
rbt_free_node(
/*==========*/
	ib_rbt_node_t*	node,			/*!< in: node to free */
	ib_rbt_node_t*	nil)			/*!< in: rb tree nil node */
{
	if (node != nil) {
		rbt_free_node(node->left, nil);
		rbt_free_node(node->right, nil);

		ut_free(node);
	}
}
Ejemplo n.º 2
0
/**********************************************************************//**
Reset the tree. Delete all the nodes. */
UNIV_INTERN
void
rbt_clear(
/*======*/
	ib_rbt_t*	tree)			/*!< in: rb tree */
{
	rbt_free_node(ROOT(tree), tree->nil);
	rbt_reset(tree);
}
Ejemplo n.º 3
0
/************************************************************************
Free all the nodes and free the tree. */
UNIV_INTERN
void
rbt_free(
/*=====*/
	ib_rbt_t*	tree)			/*!< in: rb tree to free */
{
	rbt_free_node(tree->root, tree->nil);
	ut_free(tree->nil);
	ut_free(tree);
}
Ejemplo n.º 4
0
/************************************************************************
Reset the tree. Delete all the nodes. */
UNIV_INTERN
void
rbt_clear(
/*======*/
	ib_rbt_t*	tree)			/*!< in: rb tree */
{
	rbt_free_node(ROOT(tree), tree->nil);

	tree->n_nodes = 0;
	tree->root->left = tree->root->right = tree->nil;
}
Ejemplo n.º 5
0
RBT_NODE *rbt_allocate_node( /*@in@*/ RBT_ROOT *root , uintptr_t key ,
                             void *data )
{
  RBT_NODE *node = root->alloc_fn( sizeof( RBT_NODE ) , root->data ) ;

  if ( node == NULL ) {
    return NULL ;
  }

  /* Allocate the node data if necessary. I know these allocations
     could be rolled into a single one, but the jiggery pokery to get
     proper alignment would make it too crufty. */

  if ( root->node_data_size > 0 ) {
    node->data = root->alloc_fn( root->node_data_size , root->data ) ;

    if ( node->data == NULL ) {
      rbt_free_node( root , node ) ;
      return NULL ;
    }
  }

  rbt_set_node_data( root , node , data ) ;

  /* Non-zero key length implies a binary key that needs space to be
     stored. Otherwise the key can be copied by reference or is an
     integer. */

  if ( root->key_length > 0 ) {
    node->key = ( uintptr_t )root->alloc_fn( root->key_length , root->data ) ;

    if ( node->key == ( uintptr_t )NULL ) {
      rbt_free_node( root , node ) ;
      return NULL ;
    }
  }

  rbt_set_node_key( root , node , key ) ;

  return node ;
}
Ejemplo n.º 6
0
static Bool rbt_dispose_node( RBT_ROOT *root , RBT_NODE *node , void *data )
{
  UNUSED_PARAM( void * , data ) ;
  rbt_free_node( root , node ) ;
  return TRUE ;
}