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

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

uint32_t avlnode_doublerotate (avlnode_ref s, uint32_t max, uint32_t i, int h)
{
  uint32_t j = s[i].child[!h] ;
  uint32_t k = s[j].child[h] ;
  s[i].child[!h] = s[k].child[h] ;
  s[j].child[h] = s[k].child[!h] ;
  s[k].child[!h] = j ;
  s[k].child[h] = i ;
  s[h ? i : j].balance = (s[k].balance < 0) ;
  s[h ? j : i].balance = -(s[k].balance > 0) ;
  s[k].balance = 0 ;
  (void)max ;
  return k ;
}