コード例 #1
0
ファイル: btree.c プロジェクト: taysom/tau
bool split_leaf (void *self, branch_s *parent, int k, unint len)
{
	leaf_s	*child = self;
	leaf_s	*sibling;
	int	upper;
	u64	upper_key;
FN;
	if (!leaf_is_full(child, len)) {
		return FALSE;
	}
	sibling = new_leaf(bdev(parent));

	upper = (child->l_num + 1) / 2;
	upper_key = child->l_rec[upper].r_key;

	copy_recs(sibling, child, upper);

	child->l_num = upper;
	child->l_total += (BLK_SIZE - sizeof(leaf_s)) - sibling->l_total;
	bdirty(child);
	bput(child);

	insert_sibling(parent, sibling, k, upper_key);
	bput(sibling);
	return TRUE;
}
コード例 #2
0
static bool split_leaf (tree_s *tree, leaf_s *child, branch_s *parent, s64 k, unint size)
{
	leaf_s	*sibling;
	snint	upper;
	u64	upper_key;

	if (!leaf_is_full(child, size)) {
		return FALSE;
	}
FN;
	sibling = new_leaf(tree);

	upper = (child->l_num + 1) / 2;
	upper_key = child->l_rec[upper].r_key;

	copy_recs(sibling, child, upper);

	child->l_num = upper;
	child->l_total += (BLK_SIZE - sizeof(leaf_s)) - sibling->l_total;
	tau_blog(child);
	tau_bput(child);

	insert_sibling(parent, sibling, k, upper_key);
	tau_bput(sibling);
	return TRUE;
}
コード例 #3
0
ファイル: btree.c プロジェクト: taysom/tau
void *grow_tree (tree_s *tree, unint len)
{
	void		*root;
	branch_s	*branch;
	int		rc;
FN;
	if (root_blkno(tree)) {
		root = bget(tree->t_dev, root_blkno(tree));
		if (!root) return NULL;

		switch (type(root)) {
		case LEAF:
			if (!leaf_is_full(root, len)) {
				return root;
			}
			break;
		case BRANCH:
			if (!branch_is_full(root)) {
				return root;
			}
			break;
		default:
			bput(root);
			error("Bad block");
			exit(1);
			break;
		}
		branch = new_branch(tree->t_dev);
		branch->br_first = bblkno(root);
		bput(root);
		root = branch;
	} else {
		root = new_leaf(tree->t_dev);
	}
	rc = change_root(tree, root);
	if (rc) {
		error("Couldn't grow tree");
		return NULL;
	}
	return root;
}
コード例 #4
0
static void *grow_tree (tree_s *tree, unint size)
{
	head_s		*head;
	branch_s	*branch;
	int		rc;
FN;
	if (root(tree)) {
		head = tau_bget(tree_inode(tree), root(tree));
		if (!head) return NULL;

		switch (head->h_magic) {
		case LEAF:
			if (!leaf_is_full((leaf_s *)head, size)) {
				return head;
			}
			break;
		case BRANCH:
			if (!branch_is_full((branch_s *)head)) {
				return head;
			}
			break;
		default:
			tau_bput(head);
			eprintk("Bad block");
			BUG();
			break;
		}
		branch = new_branch(tree);
		branch->br_first = tau_bnum(head);
		tau_bput(head);
		head = (head_s *)branch;
	} else {
		head = (head_s *)new_leaf(tree);
	}
	rc = change_root(tree, head);
	if (rc) {
		error("Couldn't grow tree");
		return NULL;
	}
	return head;
}
コード例 #5
0
ファイル: mtree.c プロジェクト: taysom/tau
void *grow_tree (tree_s *tree, unint size)
{
    void		*node;
    branch_s	*branch;
    int		rc;
    FN;
    node = root(tree);
    if (node) {
        switch (magic(node)) {
        case LEAF:
            if (!leaf_is_full(node, size)) {
                return node;
            }
            break;
        case BRANCH:
            if (!branch_is_full(node)) {
                return node;
            }
            break;
        default:
            eprintf("Bad node");
            break;
        }
        branch = new_branch(tree);
        branch->br_first = node;
        node = branch;
    } else {
        node = new_leaf(tree);
    }
    rc = change_root(tree, node);
    if (rc) {
        eprintf("Couldn't grow tree");
        return NULL;
    }
    return node;
}