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

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

uint32_t avlnode_rotate (avlnode *s, uint32_t max, uint32_t i, int h)
{
  uint32_t 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 ;
}