summaryrefslogtreecommitdiff
path: root/src/libdatastruct/avlnode_rotate.c
blob: fe06994f18ba16ef5c2c786bb56baae7d39f225b (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_ref 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 ;
}