Exemplo n.º 1
0
static rbtree_node* rotate_right(rbtree_node *h) {
    rbtree_node *x = h->left;
    h->left = x->right;
    x->right = set_num_nodes(h);
    x->color = x->right->color;
    x->right->color = RED;
    return set_num_nodes(x);
}
Exemplo n.º 2
0
void NetworkLowLevel::init( int* argc, char *** argv ) {
      MPI_Init(argc, argv );
      MPI_Comm_rank(MPI_COMM_WORLD, &node_num );
      MPI_Comm_size(MPI_COMM_WORLD, &num_nodes ); 
      set_node_num(node_num);
      set_num_nodes(num_nodes);
}
Exemplo n.º 3
0
static rbtree_node* fixup(rbtree_node *h) {
    if ( isred(h->right) )
        h = rotate_left(h);

    if ( isred(h->left) && isred(h->left->left) )
        h = rotate_right(h);

    if ( isred(h->left) && isred(h->right) )
        colorflip(h);

    return set_num_nodes(h);
}
Exemplo n.º 4
0
static rbtree_node* insert(rbtree *tree, rbtree_node *node, VALUE key, VALUE value) {
    int cmp;

    // This slot is empty, so we insert our new node
    if(!node) {
        rbtree_node *new_node = ALLOC(rbtree_node);
        new_node->key		= key;
        new_node->value		= value;
        new_node->color		= RED;
        new_node->height	= 1;
        new_node->num_nodes = 1;
        new_node->left		= NULL;
        new_node->right		= NULL;
        return new_node;
    }

    // Insert left or right, recursively
    cmp = tree->compare_function(key, node->key);
    if		(cmp == 0)	{
        node->value = value;
    }
    else if (cmp == -1) {
        node->left	= insert(tree, node->left, key, value);
    }
    else				{
        node->right = insert(tree, node->right, key, value);
    }

    // Fix our tree to keep left-lean
    if (isred(node->right)) {
        node = rotate_left(node);
    }
    if (isred(node->left) && isred(node->left->left)) {
        node = rotate_right(node);
    }
    if ( isred(node->left) && isred(node->right) ) {
        colorflip(node);
    }
    return set_num_nodes(node);
}