public static void Main(string[] args) { for (int j = 0; j < 100; j++) { var myText = new ImmutableText("hello"); for (int i = 0; i < 100000; i++) { myText = myText.InsertText(i, "1"); } for (int i = 0; i < 100000; i++) { myText = myText.RemoveText(0, 1); } } }
/// <summary> /// Returns the text having the specified text inserted at /// the specified location. /// </summary> /// <param name="index">index the insertion position.</param> /// <param name="txt">txt the text being inserted.</param> /// <returns>subtext(0, index).concat(txt).concat(subtext(index))</returns> /// <exception cref="IndexOutOfRangeException">if <code>(index < 0) || (index > this.Length)</code></exception> public ImmutableText InsertText(int index, ImmutableText txt) { return(GetText(0, index).Concat(txt).Concat(SubText(index))); }
/// <summary> /// Concatenates the specified text to the end of this text. /// This method is very fast (faster even than /// <code>StringBuffer.append(String)</code>) and still returns /// a text instance with an internal binary tree of minimal depth! /// </summary> /// <param name="that">that the text that is concatenated.</param> /// <returns><code>this + that</code></returns> public ImmutableText Concat(ImmutableText that) { return(that.Length == 0 ? this : Length == 0 ? that : new ImmutableText(ConcatNodes(EnsureChunked().root, that.EnsureChunked().root), encoding)); }