Rope (data structure): Difference between revisions

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
imported>Iamngoni
No edit summary
 
imported>Alexhrao
m Move table to its own row so that the advantages does not get squished
 
Line 27: Line 27:


==Operations==
==Operations==
In the following definitions, ''N'' is the length of the rope, that is, the weight of the root node.
In the following definitions, ''N'' is the length of the rope, that is, the weight of the root node. These examples are defined in the [[Java (programming language)|Java programming language]].


=== Collect leaves ===
=== Collect leaves ===
: ''Definition:'' Create a stack ''S'' and a list ''L''.  Traverse down the left-most spine of the tree until you reach a leaf l', adding each node ''n'' to ''S''.  Add l' to ''L''. The parent of l' (''p'') is at the top of the stack.  Repeat the procedure for p's right subtree.
: ''Definition:'' Create a stack ''S'' and a list ''L''.  Traverse down the left-most spine of the tree until reaching a leaf l', adding each node ''n'' to ''S''.  Add l' to ''L''. The parent of l' (''p'') is at the top of the stack.  Repeat the procedure for p's right subtree.


<syntaxhighlight lang="java">
<syntaxhighlight lang="java">
final class InOrderRopeIterator implements Iterator<RopeLike> {
package org.wikipedia.example;


import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Iterator;
import jakarta.annotation.NonNull;
class RopeLike {
    private RopeLike left;
    private RopeLike right;
    public RopeLike(RopeLike left, RopeLike right) {
        this.left = left;
        this.right = right;
    }
    public RopeLike getLeft() {
        return left;
    }
    public RopeLike getRight() {
        return right;
    }
}
public final class InOrderRopeIterator implements Iterator<RopeLike> {
     private final Deque<RopeLike> stack;
     private final Deque<RopeLike> stack;


     InOrderRopeIterator(@NonNull RopeLike root) {
     public InOrderRopeIterator(@NonNull RopeLike root) {
         stack = new ArrayDeque<>();
         stack = new ArrayDeque<>();
         var c = root;
         RopeLike c = root;
         while (c != null) {
         while (c != null) {
             stack.push(c);
             stack.push(c);
Line 53: Line 78:
     @Override
     @Override
     public RopeLike next() {
     public RopeLike next() {
         val result = stack.pop();
         RopeLike result = stack.pop();


         if (!stack.isEmpty()) {
         if (!stack.isEmpty()) {
             var parent = stack.pop();
             RopeLike parent = stack.pop();
             var right = parent.getRight();
             RopeLike right = parent.getRight();
             if (right != null) {
             if (right != null) {
                 stack.push(right);
                 stack.push(right);
                 var cleft = right.getLeft();
                 RopeLike cleft = right.getLeft();
                 while (cleft != null) {
                 while (cleft != null) {
                     stack.push(cleft);
                     stack.push(cleft);
Line 77: Line 102:


<syntaxhighlight lang="java">
<syntaxhighlight lang="java">
import java.util.List;
static boolean isBalanced(RopeLike r) {
static boolean isBalanced(RopeLike r) {
     val depth = r.depth();
     int depth = r.depth();
     if (depth >= FIBONACCI_SEQUENCE.length - 2) {
     if (depth >= FIBONACCI_SEQUENCE.length - 2) {
         return false;
         return false;
Line 87: Line 114:
static RopeLike rebalance(RopeLike r) {
static RopeLike rebalance(RopeLike r) {
     if (!isBalanced(r)) {
     if (!isBalanced(r)) {
         val leaves = Ropes.collectLeaves(r);
         List<RopeLike> leaves = Ropes.collectLeaves(r);
         return merge(leaves, 0, leaves.size());
         return merge(leaves, 0, leaves.size());
     }
     }
Line 99: Line 126:
static RopeLike merge(List<RopeLike> leaves, int start, int end) {
static RopeLike merge(List<RopeLike> leaves, int start, int end) {
     int range = end - start;
     int range = end - start;
     if (range == 1) {
     switch (range) {
         return leaves.get(start);
         case 1:
    }
            return leaves.get(start);
    if (range == 2) {
        case 2:
        return new RopeLikeTree(leaves.get(start), leaves.get(start + 1));
            return return new RopeLikeTree(leaves.get(start), leaves.get(start + 1));
        default:
            int mid = start + (range / 2);
            return new RopeLikeTree(merge(leaves, start, mid), merge(leaves, mid, end));
     }
     }
    int mid = start + (range / 2);
    return new RopeLikeTree(merge(leaves, start, mid), merge(leaves, mid, end));
}
}
</syntaxhighlight>
</syntaxhighlight>
Line 116: Line 144:
This operation can be done by a <code>Split()</code> and two <code>Concat()</code> operations. The cost is the sum of the three.
This operation can be done by a <code>Split()</code> and two <code>Concat()</code> operations. The cost is the sum of the three.
<syntaxhighlight lang="java">
<syntaxhighlight lang="java">
import javafx.util.Pair;
public Rope insert(int idx, CharSequence sequence) {
public Rope insert(int idx, CharSequence sequence) {
     if (idx == 0) {
     if (idx == 0) {
         return prepend(sequence);
         return prepend(sequence);
     }
     } else if (idx == length()) {
    if (idx == length()) {
         return append(sequence);
         return append(sequence);
    } else {
        Pair<RopeLike, RopeLike> lhs = base.split(idx);
        return new Rope(Ropes.concat(lhs.getKey().append(sequence), lhs.getValue()));
     }
     }
    val lhs = base.split(idx);
    return new Rope(Ropes.concat(lhs.fst.append(sequence), lhs.snd));
}
}
</syntaxhighlight>
</syntaxhighlight>
Line 141: Line 171:
     if (startIndex > weight) {
     if (startIndex > weight) {
         return right.indexOf(ch, startIndex - weight);
         return right.indexOf(ch, startIndex - weight);
    } else {
        return left.indexOf(ch, startIndex);
     }
     }
    return left.indexOf(ch, startIndex);
}
}
</syntaxhighlight>
</syntaxhighlight>
Line 174: Line 205:


<syntaxhighlight lang="java">
<syntaxhighlight lang="java">
import javafx.util.Pair;
public Pair<RopeLike, RopeLike> split(int index) {
public Pair<RopeLike, RopeLike> split(int index) {
     if (index < weight) {
     if (index < weight) {
         val split = left.split(index);
         Pair<RopeLike, RopeLike> split = left.split(index);
         return Pair.of(rebalance(split.fst), rebalance(new RopeLikeTree(split.snd, right)));
         return Pair.of(rebalance(split.getKey()), rebalance(new RopeLikeTree(split.getValue(), right)));
     } else if (index > weight) {
     } else if (index > weight) {
         val split = right.split(index - weight);
         Pair<RopeLike, RopeLike> split = right.split(index - weight);
         return Pair.of(rebalance(new RopeLikeTree(left, split.fst)), rebalance(split.snd));
         return Pair.of(rebalance(new RopeLikeTree(left, split.getKey())), rebalance(split.getValue()));
     } else {
     } else {
         return Pair.of(left, right);
         return Pair.of(left, right);
Line 187: Line 220:
</syntaxhighlight>
</syntaxhighlight>


=== Delete ===
=== Remove ===
: ''Definition:'' <code>Delete(i, j)</code>: delete the substring {{math|''C<sub>i</sub>'', …, ''C''<sub>''i'' + ''j'' − 1</sub>}}, from ''s'' to form a new string {{math|''C''<sub>1</sub>, …, ''C''<sub>''i'' − 1</sub>, ''C''<sub>''i'' + ''j''</sub>, …, ''C<sub>m</sub>''}}.
: ''Definition:'' <code>Remove(i, j)</code>: remove the substring {{math|''C<sub>i</sub>'', …, ''C''<sub>''i'' + ''j'' − 1</sub>}}, from ''s'' to form a new string {{math|''C''<sub>1</sub>, …, ''C''<sub>''i'' − 1</sub>, ''C''<sub>''i'' + ''j''</sub>, …, ''C<sub>m</sub>''}}.
: ''Time complexity:'' {{tmath|O(\log N)}}.
: ''Time complexity:'' {{tmath|O(\log N)}}.


This operation can be done by two <code>Split()</code> and one <code>Concat()</code> operation. First, split the rope in three, divided by ''i''-th and ''i+j''-th character respectively, which extracts the string to delete in a separate node. Then concatenate the other two nodes.
This operation can be done by two <code>Split()</code> and one <code>Concat()</code> operation. First, split the rope in three, divided by ''i''-th and ''i+j''-th character respectively, which extracts the string to remove in a separate node. Then concatenate the other two nodes.


<syntaxhighlight lang="java">
<syntaxhighlight lang="java">
import javafx.util.Pair;
@Override
@Override
public RopeLike delete(int start, int length) {
public RopeLike remove(int start, int length) {
     val lhs = split(start);
     Pair<RopeLike, RopeLike> lhs = split(start);
     val rhs = split(start + length);
     Pair<RopeLike, RopeLike> rhs = split(start + length);
     return rebalance(new RopeLikeTree(lhs.fst, rhs.snd));
     return rebalance(new RopeLikeTree(lhs.getKey(), rhs.getValue()));
}
}
</syntaxhighlight>
</syntaxhighlight>
Line 209: Line 244:


==Comparison with monolithic arrays==
==Comparison with monolithic arrays==
{| class="wikitable floatright"
Advantages:
* Ropes enable much faster insertion and deletion of text than monolithic string arrays, on which operations have time complexity O(n).
* Ropes do not require O(n) extra memory when operated upon (arrays need that for copying operations).
* Ropes do not require large contiguous memory spaces.
* If only nondestructive versions of operations are used, rope is a [[persistent data structure]]. For the text editing program example, this leads to an easy support for multiple [[undo]] levels.
 
Disadvantages:
* Greater overall space use when not being operated on, mainly to store parent nodes. There is a trade-off between how much of the total memory is such overhead and how long pieces of data are being processed as strings. The strings in example figures above are unrealistically short for modern architectures. The overhead is always O(n), but the constant can be made arbitrarily small.
* Increase in time to manage the extra storage
* Increased complexity of source code; greater risk of bugs
 
This table compares the ''algorithmic'' traits of string and rope implementations, not their ''raw speed''.  Array-based strings have smaller overhead, so (for example) concatenation and split operations are faster on small datasets. However, when array-based strings are used for longer strings, time complexity and memory use for inserting and deleting characters becomes unacceptably large. In contrast, a rope data structure has stable performance regardless of data size. Further, the space complexity for ropes and arrays are both O(n). In summary, ropes are preferable when the data is large and modified often.
 
{| class="wikitable center"
|+ Complexity{{citation needed|date=October 2010}}
|+ Complexity{{citation needed|date=October 2010}}
! Operation !! Rope !! String
! Operation !! Rope !! String
Line 229: Line 277:
}}</ref>{{Failed verification|date=September 2023}} || {{yes|O(1) amortized, O(log n) worst case}} || {{bad|O(1) amortized, O(n) worst case}}
}}</ref>{{Failed verification|date=September 2023}} || {{yes|O(1) amortized, O(log n) worst case}} || {{bad|O(1) amortized, O(n) worst case}}
|- align="center"
|- align="center"
| Delete || {{yes|O(log n)}} || {{bad|O(n)}}
| Remove || {{yes|O(log n)}} || {{bad|O(n)}}
|- align="center"
|- align="center"
| Report || {{bad|O(j + log n)}} || {{yes|O(j)}}
| Report || {{bad|O(j + log n)}} || {{yes|O(j)}}
Line 235: Line 283:
| Build || {{okay|O(n)}} || {{okay|O(n)}}
| Build || {{okay|O(n)}} || {{okay|O(n)}}
|}
|}
Advantages:
* Ropes enable much faster insertion and deletion of text than monolithic string arrays, on which operations have time complexity O(n).
* Ropes do not require O(n) extra memory when operated upon (arrays need that for copying operations).
* Ropes do not require large contiguous memory spaces.
* If only nondestructive versions of operations are used, rope is a [[persistent data structure]]. For the text editing program example, this leads to an easy support for multiple [[undo]] levels.
Disadvantages:
* Greater overall space use when not being operated on, mainly to store parent nodes. There is a trade-off between how much of the total memory is such overhead and how long pieces of data are being processed as strings. The strings in example figures above are unrealistically short for modern architectures. The overhead is always O(n), but the constant can be made arbitrarily small.
* Increase in time to manage the extra storage
* Increased complexity of source code; greater risk of bugs
This table compares the ''algorithmic'' traits of string and rope implementations, not their ''raw speed''.  Array-based strings have smaller overhead, so (for example) concatenation and split operations are faster on small datasets. However, when array-based strings are used for longer strings, time complexity and memory use for inserting and deleting characters becomes unacceptably large. In contrast, a rope data structure has stable performance regardless of data size. Further, the space complexity for ropes and arrays are both O(n). In summary, ropes are preferable when the data is large and modified often.


==See also==
==See also==
Line 272: Line 307:
*[https://nim-lang.org/docs/ropes.html ropes] for [[Nim (programming language)|Nim]]
*[https://nim-lang.org/docs/ropes.html ropes] for [[Nim (programming language)|Nim]]
*[https://github.com/Chris00/ocaml-rope Ropes] for [[OCaml]]
*[https://github.com/Chris00/ocaml-rope Ropes] for [[OCaml]]
*[http://sourceforge.net/projects/pyropes/files/?source=navbar pyropes] for [[Python (programming language)|Python]]
*[https://sourceforge.net/projects/pyropes/files/?source=navbar pyropes] for [[Python (programming language)|Python]]
*[https://github.com/KenDickey/Cuis-Smalltalk-Ropes Ropes] for [[Smalltalk]]
*[https://github.com/KenDickey/Cuis-Smalltalk-Ropes Ropes] for [[Smalltalk]]
*[https://github.com/fweez/SwiftRope SwiftRope] for [[Swift (programming language)|Swift]]
*[https://github.com/fweez/SwiftRope SwiftRope] for [[Swift (programming language)|Swift]]
Line 279: Line 314:
*[https://zed.dev/blog/zed-decoded-rope-sumtree/ Rope & SumTree] in Zed Editor
*[https://zed.dev/blog/zed-decoded-rope-sumtree/ Rope & SumTree] in Zed Editor


{{Strings |state=collapsed}}
{{Data structures}}
{{Strings}}


{{DEFAULTSORT:Rope Data Structure}}
{{DEFAULTSORT:Rope Data Structure}}
[[Category:Binary trees]]
[[Category:Binary trees]]
[[Category:String data structures]]
[[Category:String data structures]]

Latest revision as of 16:03, 17 November 2025

Template:Short description

File:Vector Rope example.svg
A simple rope built on the string of "Hello_my_name_is_Simon".

In computer programming, a rope, or cord, is a data structure composed of smaller strings that is used to efficiently store and manipulate longer strings or entire texts. For example, a text editing program may use a rope to represent the text being edited, so that operations such as insertion, deletion, and random access can be done efficiently.[1]

Description

A rope is a type of binary tree where each leaf (end node) holds a string of manageable size and length (also known as a weight), and each node further up the tree holds the sum of the lengths of all the leaves in its left subtree. A node with two children thus divides the whole string into two parts: the left subtree stores the first part of the string, the right subtree stores the second part of the string, and a node's weight is the length of the first part.

For rope operations, the strings stored in nodes are assumed to be constant immutable objects in the typical nondestructive case, allowing for some copy-on-write behavior. Leaf nodes are usually implemented as basic fixed-length strings with a reference count attached for deallocation when no longer needed, although other garbage collection methods can be used as well.

Operations

In the following definitions, N is the length of the rope, that is, the weight of the root node. These examples are defined in the Java programming language.

Collect leaves

Definition: Create a stack S and a list L. Traverse down the left-most spine of the tree until reaching a leaf l', adding each node n to S. Add l' to L. The parent of l' (p) is at the top of the stack. Repeat the procedure for p's right subtree.
package org.wikipedia.example;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Iterator;

import jakarta.annotation.NonNull;

class RopeLike {
    private RopeLike left;
    private RopeLike right;

    public RopeLike(RopeLike left, RopeLike right) {
        this.left = left;
        this.right = right;
    }

    public RopeLike getLeft() {
        return left;
    }

    public RopeLike getRight() {
        return right;
    }
}

public final class InOrderRopeIterator implements Iterator<RopeLike> {
    private final Deque<RopeLike> stack;

    public InOrderRopeIterator(@NonNull RopeLike root) {
        stack = new ArrayDeque<>();
        RopeLike c = root;
        while (c != null) {
            stack.push(c);
            c = c.getLeft();
        }
    }

    @Override
    public boolean hasNext() {
        return stack.size() > 0;
    }

    @Override
    public RopeLike next() {
        RopeLike result = stack.pop();

        if (!stack.isEmpty()) {
            RopeLike parent = stack.pop();
            RopeLike right = parent.getRight();
            if (right != null) {
                stack.push(right);
                RopeLike cleft = right.getLeft();
                while (cleft != null) {
                    stack.push(cleft);
                    cleft = cleft.getLeft();
                }
            }
        }

        return result;
    }
}

Rebalance

Definition: Collect the set of leaves L and rebuild the tree from the bottom-up.
import java.util.List;

static boolean isBalanced(RopeLike r) {
    int depth = r.depth();
    if (depth >= FIBONACCI_SEQUENCE.length - 2) {
        return false;
    }
    return FIBONACCI_SEQUENCE[depth + 2] <= r.weight();
}

static RopeLike rebalance(RopeLike r) {
    if (!isBalanced(r)) {
        List<RopeLike> leaves = Ropes.collectLeaves(r);
        return merge(leaves, 0, leaves.size());
    }
    return r;
}

static RopeLike merge(List<RopeLike> leaves) {
    return merge(leaves, 0, leaves.size());
}

static RopeLike merge(List<RopeLike> leaves, int start, int end) {
    int range = end - start;
    switch (range) {
        case 1:
            return leaves.get(start);
        case 2:
            return return new RopeLikeTree(leaves.get(start), leaves.get(start + 1));
        default:
            int mid = start + (range / 2);
            return new RopeLikeTree(merge(leaves, start, mid), merge(leaves, mid, end));
    }
}

Insert

Definition: Insert(i, S’): insert the string S’ beginning at position i in the string s, to form a new string C1, ..., Ci, S', Ci + 1, ..., CmScript error: No such module "Check for unknown parameters"..
Time complexity: Template:Tmath.

This operation can be done by a Split() and two Concat() operations. The cost is the sum of the three.

import javafx.util.Pair;

public Rope insert(int idx, CharSequence sequence) {
    if (idx == 0) {
        return prepend(sequence);
    } else if (idx == length()) {
        return append(sequence);
    } else {
        Pair<RopeLike, RopeLike> lhs = base.split(idx);
        return new Rope(Ropes.concat(lhs.getKey().append(sequence), lhs.getValue()));
    }
}

Index

File:Vector Rope index.svg
Figure 2.1: Example of index lookup on a rope.
Definition: Index(i): return the character at position i
Time complexity: Template:Tmath

To retrieve the i-th character, we begin a recursive search from the root node:

@Override
public int indexOf(char ch, int startIndex) {
    if (startIndex > weight) {
        return right.indexOf(ch, startIndex - weight);
    } else {
        return left.indexOf(ch, startIndex);
    }
}

For example, to find the character at i=10 in Figure 2.1 shown on the right, start at the root node (A), find that 22 is greater than 10 and there is a left child, so go to the left child (B). 9 is less than 10, so subtract 9 from 10 (leaving i=1) and go to the right child (D). Then because 6 is greater than 1 and there's a left child, go to the left child (G). 2 is greater than 1 and there's a left child, so go to the left child again (J). Finally 2 is greater than 1 but there is no left child, so the character at index 1 of the short string "na" (ie "n") is the answer. (1-based index)

Concat

File:Vector Rope concat.svg
Figure 2.2: Concatenating two child ropes into a single rope.
Definition: Concat(S1, S2): concatenate two ropes, S1 and S2, into a single rope.
Time complexity: Template:Tmath (or Template:Tmath time to compute the root weight)

A concatenation can be performed simply by creating a new root node with <templatestyles src="Mono/styles.css" />left = S1 and <templatestyles src="Mono/styles.css" />right = S2, which is constant time. The weight of the parent node is set to the length of the left child S1, which would take Template:Tmath time, if the tree is balanced.

As most rope operations require balanced trees, the tree may need to be re-balanced after concatenation.

Split

File:Vector Rope split.svg
Figure 2.3: Splitting a rope in half.
Definition: Split (i, S): split the string S into two new strings S1 and S2, S1 = C1, ..., CiScript error: No such module "Check for unknown parameters". and S2 = Ci + 1, ..., CmScript error: No such module "Check for unknown parameters"..
Time complexity: Template:Tmath

There are two cases that must be dealt with:

  1. The split point is at the end of a string (i.e. after the last character of a leaf node)
  2. The split point is in the middle of a string.

The second case reduces to the first by splitting the string at the split point to create two new leaf nodes, then creating a new node that is the parent of the two component strings.

For example, to split the 22-character rope pictured in Figure 2.3 into two equal component ropes of length 11, query the 12th character to locate the node K at the bottom level. Remove the link between K and G. Go to the parent of G and subtract the weight of K from the weight of D. Travel up the tree and remove any right links to subtrees covering characters past position 11, subtracting the weight of K from their parent nodes (only node D and A, in this case). Finally, build up the newly orphaned nodes K and H by concatenating them together and creating a new parent P with weight equal to the length of the left node K.

As most rope operations require balanced trees, the tree may need to be re-balanced after splitting.

import javafx.util.Pair;

public Pair<RopeLike, RopeLike> split(int index) {
    if (index < weight) {
        Pair<RopeLike, RopeLike> split = left.split(index);
        return Pair.of(rebalance(split.getKey()), rebalance(new RopeLikeTree(split.getValue(), right)));
    } else if (index > weight) {
        Pair<RopeLike, RopeLike> split = right.split(index - weight);
        return Pair.of(rebalance(new RopeLikeTree(left, split.getKey())), rebalance(split.getValue()));
    } else {
        return Pair.of(left, right);
    }
}

Remove

Definition: Remove(i, j): remove the substring Ci, …, Ci + j − 1Script error: No such module "Check for unknown parameters"., from s to form a new string C1, …, Ci − 1, Ci + j, …, CmScript error: No such module "Check for unknown parameters"..
Time complexity: Template:Tmath.

This operation can be done by two Split() and one Concat() operation. First, split the rope in three, divided by i-th and i+j-th character respectively, which extracts the string to remove in a separate node. Then concatenate the other two nodes.

import javafx.util.Pair;

@Override
public RopeLike remove(int start, int length) {
    Pair<RopeLike, RopeLike> lhs = split(start);
    Pair<RopeLike, RopeLike> rhs = split(start + length);
    return rebalance(new RopeLikeTree(lhs.getKey(), rhs.getValue()));
}

Report

Definition: Report(i, j): output the string Ci, …, Ci + j − 1Script error: No such module "Check for unknown parameters"..
Time complexity: Template:Tmath

To report the string Ci, …, Ci + j − 1Script error: No such module "Check for unknown parameters"., find the node u that contains Ci and weight(u) >= j, and then traverse T starting at node u. Output Ci, …, Ci + j − 1Script error: No such module "Check for unknown parameters". by doing an in-order traversal of T starting at node u.

Comparison with monolithic arrays

Advantages:

  • Ropes enable much faster insertion and deletion of text than monolithic string arrays, on which operations have time complexity O(n).
  • Ropes do not require O(n) extra memory when operated upon (arrays need that for copying operations).
  • Ropes do not require large contiguous memory spaces.
  • If only nondestructive versions of operations are used, rope is a persistent data structure. For the text editing program example, this leads to an easy support for multiple undo levels.

Disadvantages:

  • Greater overall space use when not being operated on, mainly to store parent nodes. There is a trade-off between how much of the total memory is such overhead and how long pieces of data are being processed as strings. The strings in example figures above are unrealistically short for modern architectures. The overhead is always O(n), but the constant can be made arbitrarily small.
  • Increase in time to manage the extra storage
  • Increased complexity of source code; greater risk of bugs

This table compares the algorithmic traits of string and rope implementations, not their raw speed. Array-based strings have smaller overhead, so (for example) concatenation and split operations are faster on small datasets. However, when array-based strings are used for longer strings, time complexity and memory use for inserting and deleting characters becomes unacceptably large. In contrast, a rope data structure has stable performance regardless of data size. Further, the space complexity for ropes and arrays are both O(n). In summary, ropes are preferable when the data is large and modified often.

ComplexityScript error: No such module "Unsubst".
Operation Rope String
Index[1] Template:Bad O(1)
Split[1] Template:Bad O(1)
Concatenate O(1) amortized, O(log n) worst caseScript error: No such module "Unsubst". Template:Bad
Iterate over each character[1] Template:Okay Template:Okay
Insert[2]Script error: No such module "Unsubst". O(log n) Template:Bad
Append[2]Script error: No such module "Unsubst". O(1) amortized, O(log n) worst case Template:Bad
Remove O(log n) Template:Bad
Report Template:Bad O(j)
Build Template:Okay Template:Okay

See also

  • The Cedar programming environment, which used ropes "almost since its inception"[1]
  • The Model T enfilade, a similar data structure from the early 1970s
  • Gap buffer, a data structure commonly used in text editors that allows efficient insertion and deletion operations clustered near the same location
  • Piece table, another data structure commonly used in text editors

References

Script error: No such module "Unsubst".

<templatestyles src="Reflist/styles.css" />

  1. a b c d e Script error: No such module "Citation/CS1".
  2. a b Script error: No such module "citation/CS1".

Script error: No such module "Check for unknown parameters".

External links

Template:Sister project

Template:Data structures Template:Strings