summaryrefslogtreecommitdiff
path: root/src/libdatastruct/avlnode_searchnode.c
blob: 40463c708bd02beaab1027a233bd264ceb2e7810 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* ISC license. */

#include <stdint.h>
#include <skalibs/functypes.h>
#include <skalibs/avlnode.h>
#include "avlnode-internal.h"

uint32_t avlnode_searchnode (avlnode const *s, uint32_t max, uint32_t r, void const *k, dtokfunc_t_ref dtok, cmpfunc_t_ref f, void *p)
{
  while (r < max)
  {
    int h = (*f)(k, (*dtok)(s[r].data, p), p) ;
    if (!h) break ;
    r = s[r].child[avlnode_ufroms(h)] ;
  }
  return r ;
}