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