Ejemplo n.º 1
0
        internal static RopeNode <T> Concat(RopeNode <T> left, RopeNode <T> right)
        {
            if (left.length == 0)
            {
                return(right);
            }
            if (right.length == 0)
            {
                return(left);
            }

            if (left.length + right.length <= NodeSize)
            {
                left = left.CloneIfShared();
                // left is guaranteed to be leaf node after cloning:
                // - it cannot be function node (due to clone)
                // - it cannot be concat node (too short)
                right.CopyTo(0, left.contents, left.length, right.length);
                left.length += right.length;
                return(left);
            }
            var concatNode = new RopeNode <T>();

            concatNode.left   = left;
            concatNode.right  = right;
            concatNode.length = left.length + right.length;
            concatNode.Rebalance();
            return(concatNode);
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     Copies the a part of the rope into the specified array.
 ///     Runs in O(lg N + M).
 /// </summary>
 /// <remarks>
 ///     This method counts as a read access and may be called concurrently to other read accesses.
 /// </remarks>
 public void CopyTo(int index, T[] array, int arrayIndex, int count)
 {
     VerifyRange(index, count);
     VerifyArrayWithRange(array, arrayIndex, count);
     root.CopyTo(index, array, arrayIndex, count);
 }