V · Strings & sequences

Rope

A tree of small strings.

The story

Editing a 100 MB document represented as a single string is O(n) per insert. Boehm et al at PARC proposed a balanced binary tree where leaves are short strings ("ropes") and internal nodes carry total-length annotations. Insert in the middle becomes O(log n).

How it works

Each leaf is a fixed-size character buffer (e.g. 64 bytes). Internal nodes have left/right children plus the total length of the left subtree. Concatenation is just a new internal node; substring is a recursive walk; insert is a split + concat.

Where it lives

Atom and VS Code (text buffer). Cedar / Plan 9 sam editor. Helix editor. The data structure inside every modern code editor for huge files.

The key insight

Without ropes, opening a 1 GB log file in a text editor on most systems would take a minute and freeze on every keystroke. The data structure makes the experience instant.