Edit text.
Keep the past.
An immutable Unicode rope and summary B+ tree for Ruby. Built for editors and language tools that need precise positions and cheap snapshots.
Version 0.1.0 supports Ruby 3.1+ with zero runtime dependencies.
- Build an 11 MB document
- 39.5 ms
- Insert one character
- 12.3 µs
- Read one line
- 1.38 µs
Measured on arm64 macOS with Ruby 4.0.2 and YJIT. Results vary by document and hardware.
Coordinates without guesswork.
Text tools speak several coordinate systems. Denebola keeps them on the same immutable value and rejects positions that split a codepoint or surrogate pair.
UTF-8 bytes
rope.bytesizeedits & slicesUnicode codepoints
Point(1, 1)row & columnUTF-16 units
utf16_offset_atlanguage toolsFive line breaks
LF · CRLF · CR · LS · PSline accessBring your own summary.
The rope is built on a generic persistent B+ tree. Give each item an immutable summary, then seek through any monotone dimension.
- Updates copy touched paths and share the rest.
- Nodes cache cumulative summaries and item counts.
- Cursors seek by bytes, characters, UTF-16, lines, or your own dimension.
tree = Denebola::Tree.new(items, summary: Weight)
tree = tree.push(next_item)
cursor = tree.cursor(:weight).seek(42)
cursor.item
cursor.summary # everything before item
Start with one require.
Install the gem, create a rope, and keep any version you still need. Every edit returns a new frozen value.
View on RubyGemsgem install denebola
require "denebola"
rope = Denebola::Rope.new("hello\nworld")
snapshot = rope
rope = rope.insert(5, ", there")
snapshot.to_s # "hello\nworld"
rope.to_s # "hello, there\nworld"