summaryrefslogtreecommitdiff
path: root/src/libdatastruct/avlnode_iter.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libdatastruct/avlnode_iter.c')
-rw-r--r--src/libdatastruct/avlnode_iter.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/libdatastruct/avlnode_iter.c b/src/libdatastruct/avlnode_iter.c
index c6064f3..e1b17de 100644
--- a/src/libdatastruct/avlnode_iter.c
+++ b/src/libdatastruct/avlnode_iter.c
@@ -4,23 +4,27 @@
struct avlnode_iter_s
{
- avlnode *s ;
+ avlnode const *s ;
unsigned int max ;
+ unsigned int cut ;
avliterfunc_t_ref f ;
void *p ;
} ;
-static int avlnode_iter_rec (struct avlnode_iter_s const *blah, unsigned int r, unsigned int h)
+static unsigned int avlnode_iter_rec (struct avlnode_iter_s const *blah, unsigned int r, unsigned int h)
{
- return (r < blah->max) ?
- avlnode_iter_rec(blah, blah->s[r].child[0], h+1)
- && (*blah->f)(blah->s[r].data, h, blah->p)
- && avlnode_iter_rec(blah, blah->s[r].child[1], h+1)
- : 1 ;
+ if (r >= blah->max) return blah->max ;
+ {
+ unsigned int res = avlnode_iter_rec(blah, blah->s[r].child[0], h+1) ;
+ if (res != blah->max) return res ;
+ }
+ if (r == blah->cut) return blah->max ;
+ if (!(*blah->f)(blah->s[r].data, h, blah->p)) return r ;
+ return avlnode_iter_rec(blah, blah->s[r].child[1], h+1) ;
}
-int avlnode_iter (avlnode *s, unsigned int max, unsigned int r, avliterfunc_t_ref f, void *p)
+unsigned int avlnode_iter_nocancel (avlnode *s, unsigned int max, unsigned int cut, unsigned int r, avliterfunc_t_ref f, void *p)
{
- struct avlnode_iter_s blah = { s, max, f, p } ;
+ struct avlnode_iter_s blah = { .s = s, .max = max, .cut = cut, .f = f, .p = p } ;
return avlnode_iter_rec(&blah, r, 0) ;
}