}
}
+static _qt_optimal_del(struct quadtree *parent, struct quadtree *node,
+ struct quadtree_ops *ops, int parents)
+{
+ struct quadtree *child[4];
+ int i, nodes_left = 0, children = 0;
+
+ for (i = 0; i < 4; i++) {
+ if (!node->child[i])
+ continue;
+
+ child[children] = node->child[i];
+ nodes_left += child[children]->children + 1;
+ node->child[i] = NULL;
+ children++;
+ }
+
+ /*
+ * Try to remove the nodes in such order that the node which
+ * has child number one quarter of the parent's child numer
+ * gets deleted first.
+ */
+
+ if (node->children <= parents / 4) {
+ quadtree_add(parent, node, ops);
+ node = NULL;
+ }
+
+ while(children) {
+
+}
+
/*
* quadtree_del - Detach a node from the tree
*
struct quadtree_ops *ops)
{
struct quadtree *parent = 0;
+ struct quadtree *n;
int i;
/*
break;
}
}
- if (i == 4) {
- printf("%s:%d Fatal! Tree inconsistency detected\n",
- __func__, __LINE__);
- trap();
- }
- /* Fix parent stats */
- quadtree_recalculate_parent_stats(node->parent, ops);
+ parent = node->parent;
/*
- * The sub branch is now detached from the main tree. Continue
- * relocating the detached branch.
+ * The sub branch is now detached from the main tree. Fix the
+ * stats.
*/
+ quadtree_recalculate_parent_stats(node->parent, ops);
- for (i = 0; i < 4; i++) {
- if (!node->child[i])
- continue;
-
- _quadtree_reposition_reqursively(node->parent, node->child[i],
- ops);
- node->child[i] = 0;
- }
+ if (node->children)
+ _qt_del_optimal(parent, node, ops, node->children);
- parent = quadtree_find_parent(node);
node->parent = 0;
node->children = 0;
node->depth = 0;
+ parent = quadtree_find_parent(parent);
validate_tree(parent);
return parent;
}