SNAPKITTYWEST's picture
push from SNAPKITTYWEST/sovereign-ide
ffc07fb verified
|
Raw History Blame Contribute Delete
1.33 kB

Layer 3 β€” Text Buffer / Rope (8000 lines target)

What This Layer Does

The core data structure for editable text: a rope (balanced binary tree of string chunks) supporting O(log n) insert, delete, and slice. Also owns the undo tree β€” a persistent branching history of all edits.

Repos That Contribute

Repo What to pull
errant QTT tagged memory for rope nodes; Linear Forth ISA pattern for undo stack
sovereign-array Lean 4 array language β€” formal proof of rope invariants; C++20 array ops as rope leaf implementation

What to Build First

  1. Rope node type β€” leaf (u8 slice) and branch (left+right child, cached length)
  2. Rope concat / split β€” fundamental O(log n) ops
  3. Rope insert / delete β€” built on concat/split
  4. Line index β€” O(log n) byte-offset to line/col
  5. Undo tree β€” persistent snapshot with branching (not linear stack)
  6. Rope invariant proofs β€” port from sovereign-array Lean 4 proofs

Key Design Constraints

  • Rope nodes allocated from Layer 0 arena; never heap-malloc after init
  • Undo tree nodes also in arena; compacted on checkpoint
  • QTT tags from errant: each rope leaf carries a provenance tag (for LSP sync)
  • Lean 4 proofs from sovereign-array must hold: size(concat(a,b)) = size(a)+size(b)