skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

avlnode_height.c (423B)


      1 /* ISC license. */
      2 
      3 #include <skalibs/avlnode.h>
      4 
      5 unsigned int avlnode_height (avlnode const *s, uint32_t max, uint32_t r)
      6 {
      7   if (r >= max) return 0 ;
      8   else if (s[r].balance) return 1 + avlnode_height(s, max, s[r].child[s[r].balance > 0]) ;
      9   else
     10   {
     11     unsigned int h1 = avlnode_height(s, max, s[r].child[0]) ;
     12     unsigned int h2 = avlnode_height(s, max, s[r].child[1]) ;
     13     return 1 + ((h1 > h2) ? h1 : h2) ;
     14   }
     15 }