summaryrefslogtreecommitdiff
path: root/src/libdatastruct/avlnode_iter.c
blob: 9e1d69849fffcb48d49b614a83b0bb9fdd292e88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* ISC license. */

#include <skalibs/avlnode.h>

struct avlnode_iter_s
{
  avlnode_ref s ;
  unsigned int max ;
  avliterfunc_t_ref f ;
  void *p ;
} ;

static 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 ;
}

int avlnode_iter (avlnode_ref s, unsigned int max, unsigned int r, avliterfunc_t_ref f, void *p)
{
  struct avlnode_iter_s blah = { s, max, f, p } ;
  return avlnode_iter_rec(&blah, r, 0) ;
}