long int children;
children = 0;
+ if (!node) {
+ printf("Attempted to validate a null pointer\n");
+ fflush(stdout);
+ trap();
+ }
+
for (i = 0; i < 4; i++) {
if (!node->child[i])
continue;
if (node->child[i]->parent != node) {
- printf("%s:%d Fatal! Tree inconsistency detected "
- "at child %d in node %p\n",
- __func__, __LINE__, i, node);
+ printf("%s:%d Fatal! Tree inconsistency detected at "
+ "child %d %p in node %p, incorrent parent %p\n",
+ __func__, __LINE__, i, node->child[i], node,
+ node->child[i]->parent);
+ fflush(stdout);
trap();
}
printf("%s:%d Fatal! Tree loop detected "
"at child %d in node %p\n",
__func__, __LINE__, i, node);
+ fflush(stdout);
trap();
}
}
printf("%s:%d Tree statistics inconsistency detected! "
"child count mismatch. Expected %ld, got %ld\n",
__func__, __LINE__, children, node->children);
+ fflush(stdout);
trap();
}
printf("%s:%d Tree statistics inconsistency detected! "
"child depth mismatch.",
__func__, __LINE__);
+ fflush(stdout);
trap();
}
}
for (i = 0; i < 4; i++)
new->child[i] = 0;
+ if (debug) {
+ printf("adding node %p to parent %p\n", new, parent);
+ fflush(stdout);
+ }
+
quadtree_recalculate_parent_stats(new, ops);
validate_tree(new);
static void _qt_optimal_del(struct quadtree *parent, struct quadtree *node,
struct quadtree_ops *ops, int parents)
{
- struct quadtree *child[4];
+ struct quadtree *child[4] = {0};
int i, children = 0, max_c, max_i;
for (i = 0; i < 4; i++) {
*/
if (node->children <= parents / 4) {
+ if (debug) {
+ printf("%d: Moving node %p away from parent %p\n",
+ __LINE__, node, parent);
+ fflush(stdout);
+ }
validate_tree(parent);
quadtree_add(parent, node, ops);
node = NULL;
if (node) {
validate_tree(parent);
+ if (debug) {
+ printf("%d: Moving node %p away from parent %p\n",
+ __LINE__, node, parent);
+ fflush(stdout);
+ }
quadtree_add(parent, node, ops);
}
}
struct quadtree *parent = 0;
int i;
+ if (debug) {
+ printf("Deleting node %p under parent %p\n",
+ node, node->parent);
+ fflush(stdout);
+ }
/*
* We are deleting the root node. This means we have to select
* a new root node and reconstruct the entire tree under it
parent->parent = 0;
continue;
}
- _quadtree_reposition_reqursively(parent,
- node->child[i],
- ops);
+ _qt_optimal_del(parent, node->child[i], ops,
+ node->children);
node->child[i] = 0;
}
break;
}
}
+ if (i == 4)
+ trap();
parent = node->parent;
*/
quadtree_recalculate_parent_stats(node->parent, ops);
- if (node->children)
- _qt_optimal_del(parent, node, ops, node->children);
+ parent = quadtree_find_parent(parent);
- node->parent = 0;
+ if (node->children) {
+ for (i = 0; i < 4; i++) {
+ if (!node->child[i])
+ continue;
- node->children = 0;
- node->depth = 0;
+ _qt_optimal_del(parent, node->child[i], ops,
+ node->children);
+ }
+ }
- parent = quadtree_find_parent(parent);
validate_tree(parent);
return parent;
}