private long rebalance_nl(final long nParent,final long n,LongArray unlinked){
  final long nL=unsharedLeft(n,unlinked);
  final long nR=unsharedRight(n,unlinked);
  if ((nL == 0 || nR == 0) && vOptIsNull(n)) {
    if (attemptUnlink_nl(nParent,n,unlinked)) {
      return fixHeight_nl(nParent);
    }
 else {
      return n;
    }
  }
  final int hN=height(n);
  final int hL0=height(nL);
  final int hR0=height(nR);
  final int hNRepl=1 + Math.max(hL0,hR0);
  final int bal=hL0 - hR0;
  if (bal > 1) {
    return rebalanceToRight_nl(nParent,n,nL,hR0,unlinked);
  }
 else   if (bal < -1) {
    return rebalanceToLeft_nl(nParent,n,nR,hL0,unlinked);
  }
 else   if (hNRepl != hN) {
    height(n,hNRepl);
    return fixHeight_nl(nParent);
  }
 else {
    return 0;
  }
}

private long rebalance_nl ( final long nParent , final long n , LongArray unlinked ) { final long nL = unsharedLeft ( n , unlinked ) ; final long nR = unsharedRight ( n , unlinked ) ; if ( ( nL == 0 || nR == 0 ) && vOptIsNull ( n ) ) { if ( attemptUnlink_nl ( nParent , n , unlinked ) ) { return fixHeight_nl ( nParent ) ; } else { return n ; } } final int hN = height ( n ) ; final int hL0 = height ( nL ) ; final int hR0 = height ( nR ) ; final int hNRepl = 1 + Math . max ( hL0 , hR0 ) ; final int bal = hL0 - hR0 ; if ( bal > 1 ) { return rebalanceToRight_nl ( nParent , n , nL , hR0 , unlinked ) ; } else if ( bal < - 1 ) { return rebalanceToLeft_nl ( nParent , n , nR , hL0 , unlinked ) ; } else if ( hNRepl != hN ) { height ( n , hNRepl ) ; return fixHeight_nl ( nParent ) ; } else { return 0 ; } }
nparent and n must be locked on entry . returns a damaged node , or null if no more rebalancing is necessary .
