Returns an array of two balanced nodes.
@param {Node} a
@param {Node} b
@param {number} toRemove
@return {Array<Node>}
766079
function shuffle(a, b, toRemove) {
	var newA = allocate(a.height, Math.min(_const.M, a.length + b.length - toRemove));
	var newB = allocate(a.height, Math.max(0, newA.length - (a.length + b.length - toRemove)));

	// Skip the slots with size M. More precise: copy the slot references
	// to the new node
	var read = 0;
	let aLen = a.length;
	let either, fromA;
	let newALen = newA.length;
	while (fromA = read < aLen, either = fromA ? a[read] : b[read - aLen], either.length % _const.M === 0) {
		let fromNewA = read < newALen;
		if (fromNewA) {
			newA[read] = either;
		} else {
			newB[read - newALen] = either;
		}
		let size = fromNewA ? a.sizes[read] : b.sizes[read - newALen];
		if (!size) {
			size = newA.sizes[read - 1] + (0, _util.length)(either);
		}
		if (fromNewA) {
			newA.sizes[read] = size;
		} else {
			newB.sizes[read - newALen] = size;
		}
		read++;
	}

	// Pulling items from left to right, caching in a slot before writing
	// it into the new nodes.
	var write = read;
	var slot = allocate(a.height - 1, 0);
	var from = 0;

	// If the current slot is still containing data, then there will be at
	// least one more write, so we do not break this loop yet.
	while (read - write - (slot.length > 0 ? 1 : 0) < toRemove && read - a.length < b.length) {
		// Find out the max possible items for copying.
		var source = getEither(a, b, read);
		var to = Math.min(_const.M - slot.length, source.length);

		// Copy and adjust size table.
		var height = slot.height,
		    sizes = height === 0 ? null : slot.sizes.slice(0);
		slot = slot.concat(source.slice(from, to));
		slot.height = height;
		if (slot.height > 0) {
			slot.sizes = sizes;
			var len = sizes.length;
			for (var i = len; i < len + to - from; i++) {
				sizes[i] = (0, _util.length)(slot[i]);
				sizes[i] += i > 0 ? slot.sizes[i - 1] : 0;
			}
		}

		from += to;

		// Only proceed to next slots[i] if the current one was
		// fully copied.
		if (source.length <= to) {
			read++;
			from = 0;
		}

		// Only create a new slot if the current one is filled up.
		if (slot.length === _const.M) {
			saveSlot(newA, newB, write, slot);
			slot = allocate(a.height - 1, 0);
			write++;
		}
	}

	// Cleanup after the loop. Copy the last slot into the new nodes.
	if (slot.length > 0) {
		saveSlot(newA, newB, write, slot);
		write++;
	}

	// Shift the untouched slots to the left
	while (read < a.length + b.length) {
		saveSlot(newA, newB, write, getEither(a, b, read));
		read++;
		write++;
	}

	return [newA, newB];
}
873899
function levelSorter(a, b) {
  var l = Math.max(a.length, b.length)
  for (var i = 0; i < l; i += 1) {
    if (!(i in a)) return +1
    if (!(i in b)) return -1

    if (a.length < b.length) return +1
    if (a.length > b.length) return -1
  }
}
872746
private Node<K, V> joinLR(Node<K, V> a, Node<K, V> b) {
    if (a == null) {
      return b;
    }
    if (b == null) {
      return a;
    }

    if (java.lang.Math.random() * (size(a) + size(b)) < size(a)) {
      a.right = joinLR(a.right, b);
      fix(a);
      return a;
    } else {
      b.left = joinLR(a, b.left);
      fix(b);
      return b;
    }
  }
435088
function compareCollapsedMarkers(a, b) {
    var lenDiff = a.lines.length - b.lines.length;
    if (lenDiff != 0) return lenDiff;
    var aPos = a.find(), bPos = b.find();
    var fromCmp = cmp(aPos.from, bPos.from) || extraLeft(a) - extraLeft(b);
    if (fromCmp) return -fromCmp;
    var toCmp = cmp(aPos.to, bPos.to) || extraRight(a) - extraRight(b);
    if (toCmp) return toCmp;
    return b.id - a.id;
  }
948407
function mergable(a, b) {
	return a.nodeName === b.nodeName && similar(a, b);
}
915281
function compareCells(a, b) {
  var n = a.length
    , t = a.length - b.length
    , min = Math.min
  if(t) {
    return t
  }
  switch(n) {
    case 0:
      return 0;
    case 1:
      return a[0] - b[0];
    case 2:
      var d = a[0]+a[1]-b[0]-b[1]
      if(d) {
        return d
      }
      return min(a[0],a[1]) - min(b[0],b[1])
    case 3:
      var l1 = a[0]+a[1]
        , m1 = b[0]+b[1]
      d = l1+a[2] - (m1+b[2])
      if(d) {
        return d
      }
      var l0 = min(a[0], a[1])
        , m0 = min(b[0], b[1])
        , d  = min(l0, a[2]) - min(m0, b[2])
      if(d) {
        return d
      }
      return min(l0+a[2], l1) - min(m0+b[2], m1)
    
    //TODO: Maybe optimize n=4 as well?
    
    default:
      var as = a.slice(0)
      as.sort()
      var bs = b.slice(0)
      bs.sort()
      for(var i=0; i<n; ++i) {
        t = as[i] - bs[i]
        if(t) {
          return t
        }
      }
      return 0
  }
}
340222
function intersects(a, b) {
	return a.position[0] < b.position[0] + b.size[0] && a.position[0] + a.size[0] > b.position[0]
	    && a.position[1] < b.position[1] + b.size[1] && a.position[1] + a.size[1] > b.position[1]
}
201429
function mergeObjects(a, b) {
    var r = { };
    for (var k in a)
        r[k] = a[k];
    for (var k in b)
        r[k] = b[k];
    return r;
}
1007306
function (array1, array2) {
                return array1.every(function (element) {
                    return array2.includes(element);
                }) && array1.length === array2.length;
            }
252183
function( a, b, aParent, bParent, prop, compares, options ) {
		if(Array.isArray(a) && Array.isArray(b) ) {
			var intersection = [];
			each(makeArray(a), function(cur){
				for(var i = 0; i < b.length; i++) {
					if( compareHelpers.equal(cur, b[i], aParent, bParent, undefined, compares['*'], {"default": false}) ) {
						intersection.push(cur);
						break;
					}
				}
			});
			options.result[prop] = intersection;
			return true;
		}
	}
785338
function merge (a, b) {
    var result = {};
    var x;

    for (x in a) {
      if (a.hasOwnProperty(x)) {
        result[x] = a[x];
      }
    }

    for (x in b) {
      if (b.hasOwnProperty(x)) {
        result[x] = b[x];
      }
    }

    return result;
  }
890454
function vecSub(a, b) {

  return [
  new Fraction(a[0]).sub(b[0]),
  new Fraction(a[1]).sub(b[1])
  ];
}
898055
function calcToRemove(a, b)
{
	var subLengths = 0;
	for (var i = 0; i < a.table.length; i++)
	{
		subLengths += a.table[i].table.length;
	}
	for (var i = 0; i < b.table.length; i++)
	{
		subLengths += b.table[i].table.length;
	}

	var toRemove = a.table.length + b.table.length;
	return toRemove - (Math.floor((subLengths - 1) / M) + 1);
}
1096697
function thunks(a, b, patch, index) {
    var nodes = handleThunk(a, b);
    var thunkPatch = diff(nodes.a, nodes.b)
    if (hasPatches(thunkPatch)) {
        patch[index] = new VPatch(VPatch.THUNK, null, thunkPatch)
    }
}
351377
function(a, b) {

            function sort(object) {
                if (typeof object !== "object" || object === null) {
                    return object;
                }

                return Object.keys(object).sort().map(function(key) {
                    return {
                        key: key,
                        value: sort(object[key])
                    };
                });
            }

            return JSON.stringify(sort(a)) === JSON.stringify(sort(b));
        }
627754
function objMerge(a, b) {
	var obj = {};

	Object.keys(a).forEach(function (key) {
		obj[key] = a[key];
	});

	Object.keys(b).forEach(function (key) {
		obj[key] = b[key];
	});

	return obj;
}
799496
function r(a, b) {
        var c = b - a;
        var arr = new Array(c);
        while (c--)
            arr[c] = --b;
        return arr;
    }