function rebalanceAlongPath(node, path) {
		var newRoot = node, 
			rotated, i;
		if (!node.hasOwnProperty('key')) { delete node.height; return node; }   // Empty tree
		// Rebalance the tree and update all heights
		for (i = path.length - 1; i >= 0; i -= 1) {
			path[i].height = 1 + Math.max(path[i].left ? path[i].left.height : 0, path[i].right ? path[i].right.height : 0);
			if (balanceFactor(path[i]) > 1) {
				rotated = rightTooSmall(path[i]);
				if (i === 0) { newRoot = rotated; }
			}
			if (balanceFactor(path[i]) < -1) {
				rotated = leftTooSmall(path[i]);
				if (i === 0) { newRoot = rotated; }
			}
		}
		return newRoot;
	}
/**
	 * Rebalance the tree along the given path. The path is given reversed (as he was calculated
	 * in the insert and delete functions).
	 * Returns the new root of the tree
	 * Of course, the first element of the path must be the root of the tree
	 */
Rebalance the tree along the given path. The path is given reversed (as he was calculated
in the insert and delete functions).
Returns the new root of the tree
Of course, the first element of the path must be the root of the tree
Rebalance the tree along the given path . The path is given reversed ( as he was calculated in the insert and delete functions ) . Returns the new root of the tree Of course the first element of the path must be the root of the tree
function rebalanceAlongPath(node, path) {
		var newRoot = node, 
			rotated, i;
		if (!node.hasOwnProperty('key')) { delete node.height; return node; }   
		for (i = path.length - 1; i >= 0; i -= 1) {
			path[i].height = 1 + Math.max(path[i].left ? path[i].left.height : 0, path[i].right ? path[i].right.height : 0);
			if (balanceFactor(path[i]) > 1) {
				rotated = rightTooSmall(path[i]);
				if (i === 0) { newRoot = rotated; }
			}
			if (balanceFactor(path[i]) < -1) {
				rotated = leftTooSmall(path[i]);
				if (i === 0) { newRoot = rotated; }
			}
		}
		return newRoot;
	}
function rebalanceAlongPath ( node , path ) { var newRoot = node , rotated , i ; if ( ! node . hasOwnProperty ( 'key' ) ) { delete node . height ; return node ; } for ( i = path . length - 1 ; i >= 0 ; i -= 1 ) { path [ i ] . height = 1 + Math . max ( path [ i ] . left ? path [ i ] . left . height : 0 , path [ i ] . right ? path [ i ] . right . height : 0 ) ; if ( balanceFactor ( path [ i ] ) > 1 ) { rotated = rightTooSmall ( path [ i ] ) ; if ( i === 0 ) { newRoot = rotated ; } } if ( balanceFactor ( path [ i ] ) < - 1 ) { rotated = leftTooSmall ( path [ i ] ) ; if ( i === 0 ) { newRoot = rotated ; } } } return newRoot ; }
Rebalance the tree along the given path.
Rebalance the tree along the given path .
// Empty tree // Rebalance the tree and update all heights