function append_(a, b)
{
	if (a.height === 0 && b.height === 0)
	{
		return [a, b];
	}

	if (a.height !== 1 || b.height !== 1)
	{
		if (a.height === b.height)
		{
			a = nodeCopy(a);
			b = nodeCopy(b);
			var appended = append_(botRight(a), botLeft(b));

			insertRight(a, appended[1]);
			insertLeft(b, appended[0]);
		}
		else if (a.height > b.height)
		{
			a = nodeCopy(a);
			var appended = append_(botRight(a), b);

			insertRight(a, appended[0]);
			b = parentise(appended[1], appended[1].height + 1);
		}
		else
		{
			b = nodeCopy(b);
			var appended = append_(a, botLeft(b));

			var left = appended[0].table.length === 0 ? 0 : 1;
			var right = left === 0 ? 1 : 0;
			insertLeft(b, appended[left]);
			a = parentise(appended[right], appended[right].height + 1);
		}
	}

	// Check if balancing is needed and return based on that.
	if (a.table.length === 0 || b.table.length === 0)
	{
		return [a, b];
	}

	var toRemove = calcToRemove(a, b);
	if (toRemove <= E)
	{
		return [a, b];
	}
	return shuffle(a, b, toRemove);
}
// Returns an array of two nodes; right and left. One node _may_ be empty.
Returns an array of two nodes; right and left. One node _may_ be empty.
Returns an array of two nodes ; right and left . One node _may_ be empty .
function append_(a, b)
{
	if (a.height === 0 && b.height === 0)
	{
		return [a, b];
	}
	if (a.height !== 1 || b.height !== 1)
	{
		if (a.height === b.height)
		{
			a = nodeCopy(a);
			b = nodeCopy(b);
			var appended = append_(botRight(a), botLeft(b));
			insertRight(a, appended[1]);
			insertLeft(b, appended[0]);
		}
		else if (a.height > b.height)
		{
			a = nodeCopy(a);
			var appended = append_(botRight(a), b);
			insertRight(a, appended[0]);
			b = parentise(appended[1], appended[1].height + 1);
		}
		else
		{
			b = nodeCopy(b);
			var appended = append_(a, botLeft(b));
			var left = appended[0].table.length === 0 ? 0 : 1;
			var right = left === 0 ? 1 : 0;
			insertLeft(b, appended[left]);
			a = parentise(appended[right], appended[right].height + 1);
		}
	}
	if (a.table.length === 0 || b.table.length === 0)
	{
		return [a, b];
	}
	var toRemove = calcToRemove(a, b);
	if (toRemove <= E)
	{
		return [a, b];
	}
	return shuffle(a, b, toRemove);
}
function append_ ( a , b ) { if ( a . height === 0 && b . height === 0 ) { return [ a , b ] ; } if ( a . height !== 1 || b . height !== 1 ) { if ( a . height === b . height ) { a = nodeCopy ( a ) ; b = nodeCopy ( b ) ; var appended = append_ ( botRight ( a ) , botLeft ( b ) ) ; insertRight ( a , appended [ 1 ] ) ; insertLeft ( b , appended [ 0 ] ) ; } else if ( a . height > b . height ) { a = nodeCopy ( a ) ; var appended = append_ ( botRight ( a ) , b ) ; insertRight ( a , appended [ 0 ] ) ; b = parentise ( appended [ 1 ] , appended [ 1 ] . height + 1 ) ; } else { b = nodeCopy ( b ) ; var appended = append_ ( a , botLeft ( b ) ) ; var left = appended [ 0 ] . table . length === 0 ? 0 : 1 ; var right = left === 0 ? 1 : 0 ; insertLeft ( b , appended [ left ] ) ; a = parentise ( appended [ right ] , appended [ right ] . height + 1 ) ; } } if ( a . table . length === 0 || b . table . length === 0 ) { return [ a , b ] ; } var toRemove = calcToRemove ( a , b ) ; if ( toRemove <= E ) { return [ a , b ] ; } return shuffle ( a , b , toRemove ) ; }
Returns an array of two nodes; right and left.
Returns an array of two nodes ; right and left .
// Check if balancing is needed and return based on that.