public ConcatenationRopeEnumerator(ConcatenationRope concatenationRope, int start)
        {
            this.initialRope = concatenationRope;
            this.toTraverse  = new RopeDeque();
            this.toTraverse.Add(concatenationRope);
            this.currentRope = null;
            this.initStart   = start;
            this.Init();

            if (start < 0 || start > concatenationRope.Length())
            {
                throw new ArgumentOutOfRangeException("Rope index out of range: " + start);
            }

            this.MoveNext(start);
        }
Exemple #2
0
        /// <summary>
        /// Concatenates two ropes together using the most efficient implementation
        /// </summary>
        /// <param name="left">the rope to come first in the new rope</param>
        /// <param name="right">te rope to come last in the new rope</param>
        /// <returns>the concatenated rope</returns>
        public Rope Concatenate(Rope left, Rope right)
        {
            if (left.Length() == 0)
            {
                return(right);
            }
            if (right.Length() == 0)
            {
                return(left);
            }

            if ((long)left.Length() + right.Length() > int.MaxValue)
            {
                throw new ArgumentOutOfRangeException("Concatenation would overflow field length");
            }

            if (left.Length() + right.Length() < COMBINE_LENGTH)
            {
                return(new FlatCharArrayRope(left.ToString(), right.ToString()));
            }
            else if (!(left is ConcatenationRope))
            {
                if (right is ConcatenationRope)
                {
                    ConcatenationRope cRight = (ConcatenationRope)right;
                    if (left.Length() + cRight.GetLeft().Length() < COMBINE_LENGTH)
                    {
                        return(this.AutoRebalance(new ConcatenationRope(new FlatCharArrayRope(left.ToString(), cRight.GetLeft().ToString()), cRight.GetRight())));
                    }
                }
            }
            else if (!(right is ConcatenationRope))
            {
                if (left is ConcatenationRope)
                {
                    ConcatenationRope cLeft = (ConcatenationRope)left;
                    if (right.Length() + cLeft.GetRight().Length() < COMBINE_LENGTH)
                    {
                        return(this.AutoRebalance(new ConcatenationRope(cLeft.GetLeft(), new FlatCharArrayRope(cLeft.GetRight().ToString(), right.ToString()))));
                    }
                }
            }

            return(this.AutoRebalance(new ConcatenationRope(left, right)));
        }
Exemple #3
0
 public ConcatenationRopeReverseEnumerator(ConcatenationRope concatenationRope, int start) : this(concatenationRope)
 {
     this.start = start;
 }
Exemple #4
0
 public ConcatenationRopeReverseEnumerator(ConcatenationRope concatenationRope)
 {
     this.concatenationRope = concatenationRope;
 }
 public ConcatenationRopeEnumerator(ConcatenationRope concatenationRope) : this(concatenationRope, 0)
 {
 }