* account at all.
*/
-struct quadtree *quadtree_add(struct quadtree *parent,
- struct quadtree *new,
- int (*compare)(struct quadtree *a,
- struct quadtree *b))
+struct quadtree *quadtree_add(struct quadtree *parent, struct quadtree *new,
+ struct quadtree_ops *ops)
{
int ret;
if (parent == new)
validate_tree(parent);
- ret = compare(parent, new);
+ ret = ops->compare(parent, new);
if (ret < 0 || ret >= 4) {
printf("Invalid comparison result of %d\n", ret);
}
if (parent->child[ret])
- return quadtree_add(parent->child[ret], new, compare);
+ return quadtree_add(parent->child[ret], new, ops);
parent->child[ret] = new;
new->parent = parent;
static void
_quadtree_reposition_reqursively(struct quadtree *root,
struct quadtree *node,
- int (*compare)(struct quadtree *a,
- struct quadtree *b))
+ struct quadtree_ops *ops)
{
int i;
node->child[i] == node->parent)
trap();
- _quadtree_reposition_reqursively(root, node->child[i], compare);
+ _quadtree_reposition_reqursively(root, node->child[i], ops);
node->child[i] = 0;
}
node->children = 0;
/* Then remove this node under the new root. */
- quadtree_add(root, node, compare);
+ quadtree_add(root, node, ops);
}
/*
* value will be the original root of the tree.
*/
struct quadtree *quadtree_del(struct quadtree *node,
- int (*compare)(struct quadtree *a,
- struct quadtree *b))
+ struct quadtree_ops *ops)
{
struct quadtree *parent = 0;
int i;
}
_quadtree_reposition_reqursively(parent,
node->child[i],
- compare);
+ ops);
node->child[i] = 0;
}
continue;
_quadtree_reposition_reqursively(node->parent, node->child[i],
- compare);
+ ops);
node->child[i] = 0;
}