From ad151c6f4cec970b140002230458a186922d0fe9 Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Thu, 8 Apr 2010 19:23:24 +0300 Subject: [PATCH] quadtree: Pass quadtree iterator structure to the callback functions This is better than plain void pointer, since now the iterator can be embedded as part of some other struct. This simplifies the design. Signed-off-by: Timo Kokkonen --- quadtree.c | 4 ++-- quadtree.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/quadtree.c b/quadtree.c index 327ee20..66cdf28 100644 --- a/quadtree.c +++ b/quadtree.c @@ -212,7 +212,7 @@ static int _walk_tree(struct quadtree *head, const struct quadtree_iterator *it) { int direction, count = 0; - direction = it->direction(head, it->ptr); + direction = it->direction(head, (struct quadtree_iterator *)it); if ((direction & QUADTREE_UPLEFT) && head->child[0]) count += _walk_tree(head->child[0], it); @@ -227,7 +227,7 @@ static int _walk_tree(struct quadtree *head, const struct quadtree_iterator *it) count += _walk_tree(head->child[3], it); if ((direction & QUADTREE_SELF) && it->callback) { - it->callback(head, it->ptr); + it->callback(head, (struct quadtree_iterator *)it); count++; } diff --git a/quadtree.h b/quadtree.h index a97619b..23b79ce 100644 --- a/quadtree.h +++ b/quadtree.h @@ -25,8 +25,8 @@ struct quadtree_iterator { struct quadtree *head; void *ptr; - int (*direction)(struct quadtree *head, void *ptr); - void (*callback)(struct quadtree *head, void *ptr); + int (*direction)(struct quadtree *head, struct quadtree_iterator *it); + void (*callback)(struct quadtree *head, struct quadtree_iterator *it); }; struct quadtree *quadtree_add(struct quadtree *parent, -- 2.44.0