Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
parent->child[ret] = new;
new->parent = parent;
parent->child[ret] = new;
new->parent = parent;
- quadtree_recalculate_parent_stats(parent);
+ quadtree_recalculate_parent_stats(new, ops);
- quadtree_recalculate_parent_stats(node->parent);
+ quadtree_recalculate_parent_stats(node->parent, ops);
/*
* The sub branch is now detached from the main tree. Continue
/*
* The sub branch is now detached from the main tree. Continue
+ /*
+ * 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);
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)
};
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.
*/
* 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)
node->children += node->child[i]->children + 1;
}
node->children += node->child[i]->children + 1;
}
+ if (ops->recalculate_stats)
+ ops->recalculate_stats(node);
+