avlnode_iter.c (851B)
1 /* ISC license. */ 2 3 #include <stdint.h> 4 #include <skalibs/avlnode.h> 5 6 struct avlnode_iter_s 7 { 8 avlnode const *s ; 9 uint32_t max ; 10 uint32_t cut ; 11 avliter_func_ref f ; 12 void *p ; 13 } ; 14 15 static uint32_t avlnode_iter_rec (struct avlnode_iter_s const *blah, uint32_t r, unsigned int h) 16 { 17 if (r >= blah->max) return blah->max ; 18 { 19 uint32_t res = avlnode_iter_rec(blah, blah->s[r].child[0], h+1) ; 20 if (res != blah->max) return res ; 21 } 22 if (r == blah->cut) return blah->max ; 23 if (!(*blah->f)(blah->s[r].data, h, blah->p)) return r ; 24 return avlnode_iter_rec(blah, blah->s[r].child[1], h+1) ; 25 } 26 27 uint32_t avlnode_iter_nocancel (avlnode *s, uint32_t max, uint32_t cut, uint32_t r, avliter_func_ref f, void *p) 28 { 29 struct avlnode_iter_s blah = { .s = s, .max = max, .cut = cut, .f = f, .p = p } ; 30 return avlnode_iter_rec(&blah, r, 0) ; 31 }