From: Timo Kokkonen Date: Mon, 5 Apr 2010 08:42:15 +0000 (+0300) Subject: quadtree: Implement quadtree_find_parent X-Git-Url: http://git.itanic.dy.fi/?p=sdl-planets;a=commitdiff_plain;h=645c46fa111deeba2ab782c96d300ba2ddb5bdf1 quadtree: Implement quadtree_find_parent This helper function simply returns the highest parent of a given node. Signed-off-by: Timo Kokkonen --- diff --git a/quadtree.h b/quadtree.h index 94c02cd..5631013 100644 --- a/quadtree.h +++ b/quadtree.h @@ -36,4 +36,14 @@ struct quadtree *quadtree_add(struct quadtree *parent, int walk_tree(const struct quadtree_iterator *iterator); + +/* quadtree_find_parent - return the highest parent of the node */ +static inline struct quadtree *quadtree_find_parent(struct quadtree *node) +{ + while (node->parent) + node = node->parent; + + return node; +} + #endif