Exemple #1
0
void image::insert_tile_with_border(int32_t x, int32_t y, uint32_t width, uint32_t height,
                                    const image& other, uint32_t x1, uint32_t x2, uint32_t y1, uint32_t y2)
{
	uint32_t x3 = other.width;
	uint32_t y3 = other.height;
	
	uint32_t w1 = x1-0;
	uint32_t w2 = x2-x1;
	uint32_t w3 = x3-x2;
	uint32_t h1 = y1-0;
	uint32_t h2 = y2-y1;
	uint32_t h3 = y3-y2;
	
	image sub;
	
	insert_sub(x,          y,           other, 0,  0,  x1, y1); // top left
	sub.init_ref_sub(other, x1, 0,  w2, h1); insert_tile(x+x1,       y,           width-w1-w3, h1,           sub); // top
	insert_sub(x+width-w3, y,           other, x2, 0,  w3, y1); // top right
	
	sub.init_ref_sub(other, 0,  y1, w1, h2); insert_tile(x,          y+y1,        w1,          height-h1-h3, sub); // left
	sub.init_ref_sub(other, x1, y1, w2, h2); insert_tile(x+x1,       y+y1,        width-w1-w3, height-h1-h3, sub); // middle
	sub.init_ref_sub(other, x2, y1, w3, h2); insert_tile(x+width-w3, y+y1,        w3,          height-h1-h3, sub); // right
	
	insert_sub(x,          y+height-h3, other, 0,  y2, x1, h3); // bottom left
	sub.init_ref_sub(other, x1, y2, w2, h3); insert_tile(x+x1,       y+height-h3, width-w1-w3, h3,           sub); // bottom
	insert_sub(x+width-w3, y+height-h3, other, x2, y2, w3, h3); // bottom right
}
Exemple #2
0
static Node * insert_sub(Tree *tree, Node *current, uintptr_t value, Node *node)
{
	int cmp;

	if (current == NIL) {
		/*
		 * Init node as late as possible, to avoid corrupting
		 * the tree in case it is already added.
		 */
		node->left = node->right = NIL;
		node->level = 1;

		tree->count++;
		return node;
	}

	/* recursive insert */
	cmp = tree->node_cmp(value, current);
	if (cmp > 0)
		current->right = insert_sub(tree, current->right, value, node);
	else if (cmp < 0)
		current->left = insert_sub(tree, current->left, value, node);
	else
		/* already exists? */
		return current;

	return rebalance_on_insert(current);
}
Exemple #3
0
void aatree_insert(Tree *tree, uintptr_t value, Node *node)
{
	tree->root = insert_sub(tree, tree->root, value, node);
}