Exemple #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");
     }
     if (input is Rope <T> inputRope)
     {
         // clone ropes instead of copying them
         inputRope.root.Publish();
         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);
             root = RopeNode <T> .CreateFromArray(arr, 0, arr.Length);
         }
     }
     root.CheckInvariants();
 }
Exemple #2
0
 public Rope(IEnumerable <T> input)
 {
     if (input is null)
     {
         throw new ArgumentNullException("input");
     }
     if (input is Rope <T> inputRope)
     {
         // clone ropes instead of copying them
         inputRope.root.Publish();
         root = inputRope.root;
     }
     else
     {
         string text = input as string;
         if (!(text is null))
         {
             // if a string is IEnumerable<T>, then T must be char
             ((Rope <char>)(object) this).root = CharRope.InitFromString(text);
         }