parent->child[ret] = new;
new->parent = parent;
- quadtree_recalculate_parent_stats(parent);
+ quadtree_recalculate_parent_stats(new, ops);
validate_tree(new);
}
/* Fix parent stats */
- quadtree_recalculate_parent_stats(node->parent);
+ quadtree_recalculate_parent_stats(node->parent, ops);
/*
* The sub branch is now detached from the main tree. Continue
};
struct quadtree_ops {
+ /*
+ * Comparison function that is needed to find out the correct
+ * location for a node in the tree
+ */
int (*compare)(struct quadtree *a, struct quadtree *b);
+
+ /*
+ * Calculates required statistical information for a node
+ */
+ void (*recalculate_stats)(struct quadtree *node);
};
static inline void init_quadtree(struct quadtree *t)
* Recursively walk through the tree and propagate changes made to the
* given node up until the highest parent.
*/
-static inline void quadtree_recalculate_parent_stats(struct quadtree *node)
+static inline void quadtree_recalculate_parent_stats(struct quadtree *node,
+ struct quadtree_ops *ops)
{
int i;
node->children += node->child[i]->children + 1;
}
+ if (ops->recalculate_stats)
+ ops->recalculate_stats(node);
+
node = node->parent;
}
}