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

#include <skalibs/genset.h>
#include <skalibs/avlnode.h>
#include <skalibs/avltreen.h>

unsigned int avltreen_newnode (avltreen *t, unsigned int d)
{
  register unsigned int i = genset_new(&t->x) ;
  if (i < avltreen_totalsize(t))
  {
    register avlnode *s = avltreen_nodes(t) ;
    s[i].data = d ;
    s[i].child[0] = s[i].child[1] = avltreen_totalsize(t) ;
    s[i].balance = 0 ;
  }
  return i ;
}