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

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

unsigned int avlnode_rotate (avlnode *s, unsigned int max, unsigned int i, int h)
{
  register unsigned int j = s[i].child[!h] ;
  s[i].child[!h] = s[j].child[h] ;
  s[j].child[h] = i ;
  if (s[j].balance * avlnode_sfromu(h) < 0) s[i].balance = s[j].balance = 0 ;
  else s[j].balance = avlnode_sfromu(h) ;
  (void)max ;
  return j ;
}