Example #1
0
        private static ConcateRope CreateRope(int depth, int length)
        {
            Debug.Assert(depth >= 1);

            var numOfParts = depth + 1;
            var lengthOfParts = length / numOfParts;

            var primitiveRope = new FlatRope(new String(' ', lengthOfParts));

            Rope rope = primitiveRope;
            for (var i = 1; i < numOfParts; i++) {
                if (i < numOfParts - 1) {
                    rope = new ConcateRope(rope, primitiveRope);
                }
                else {
                    var lastRope = new FlatRope(new String(' ', length - rope.Length));
                    rope = new ConcateRope(rope, lastRope);
                }
            }

            var concateRope = rope.As<ConcateRope>();
            Debug.Assert(concateRope.Depth == depth);
            Debug.Assert(concateRope.Length == length);

            return concateRope;
        }
Example #2
0
 public SubStringRope(FlatRope rope, int offset, int length)
 {
     if (length < 0 || offset < 0 || offset + length > rope.Length())
     {
         throw new IndexOutOfRangeException("Invalid substring offset (" + offset + ") and length (" + length + ")");
     }
     this.rope   = rope;
     this.offset = offset;
     this.length = length;
 }