Beispiel #1
0
        /// <summary>
        /// Creates a rope from the specified input.
        /// This operation runs in O(N).
        /// </summary>
        /// <exception cref="ArgumentNullException">input is null.</exception>
        public Rope(IEnumerable <T> input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            Rope <T> inputRope = input as Rope <T>;

            if (inputRope != null)
            {
                // clone ropes instead of copying them
                inputRope.root.Publish();
                this.root = inputRope.root;
            }
            else
            {
                string text = input as string;
                if (text != null)
                {
                    // if a string is IEnumerable<T>, then T must be char
                    ((Rope <char>)(object) this).root = CharRope.InitFromString(text);
                }
                else
                {
                    T[] arr = ToArray(input);
                    this.root = RopeNode <T> .CreateFromArray(arr, 0, arr.Length);
                }
            }
            this.root.CheckInvariants();
        }
Beispiel #2
0
        /// <summary>
        /// Creates a rope from a part of the array.
        /// This operation runs in O(N).
        /// </summary>
        /// <exception cref="ArgumentNullException">input is null.</exception>
        public Rope(T[] array, int arrayIndex, int count)
        {
            VerifyArrayWithRange(array, arrayIndex, count);
            this.root = RopeNode <T> .CreateFromArray(array, arrayIndex, count);

            this.root.CheckInvariants();
        }
Beispiel #3
0
        internal static RopeNode <char> InitFromString(string text)
        {
            char[] arr = text.ToCharArray();
            return(RopeNode <char> .CreateFromArray(arr, 0, arr.Length));

            /*
             * if (text.Length == 0) {
             *      return RopeNode<char>.emptyRopeNode;
             * }
             * RopeNode<char> node = RopeNode<char>.CreateNodes(text.Length);
             * // 'TODO: store data
             * return node;
             */
        }