rope 0.0.1 copy "rope: ^0.0.1" to clipboard
rope: ^0.0.1 copied to clipboard

A fast, immutable rope data structure in Dart using a SumTree architecture. Inspired by Zed's implementation, this rope is optimized for large-scale string manipulation and editor-like use cases.

Rope Dart #

A fast, immutable rope data structure in Dart using a SumTree architecture. Inspired by Zed's implementation, this rope is optimized for large-scale string manipulation and editor-like use cases.


Developed with ๐Ÿ’™ by Ngonidzashe Mangudya

style: very good analysis License: MIT


๐Ÿ”ง Features #

  • SumTree-based architecture with node-level summaries
  • Efficient insert, delete, split, concat, substring, charAt
  • Multi-line and character-aware summaries (TextSummary)
  • Designed for speed, immutability, and extensibility

๐Ÿ“ฆ Installation #

dependencies:
  rope:
    git:
      url: https://github.com/iamngoni/rope.git

Or

dependencies:
  rope: <version>

๐Ÿงฑ What is a Rope? #

A rope is a tree-based data structure for storing and editing large strings efficiently. Zed uses a generalized B+ tree called a SumTree, where each node summarizes its subtree (e.g., character length, line count).

This enables:

  • O(log n) character access and mutation
  • Efficient line/column โ†” offset conversion
  • Concurrent snapshotting & persistence

๐Ÿ›  Example Usage #

void main() {
  final rope = Rope.fromString("Hello World!");

  final inserted = rope.insert(5, ", beautiful");
  print(inserted); // Hello, beautiful World!

  final deleted = inserted.delete(5, 16);
  print(deleted); // Hello World!

  final char = rope.charAt(1);
  print(char); // e

  final substring = rope.substring(0, 5);
  print(substring); // Hello

  final (left, right) = rope.split(6);
  print(left);  // Hello
  print(right); // World!
}

๐Ÿงช Running Tests #

Use the test package:

dart test

๐Ÿง  Internals #

Each rope is a SumTree of Chunk nodes:

class Rope {
  final SumTreeNode<Chunk> root;
}

Each node maintains a TextSummary:

class TextSummary {
  final int length;
  final int lines;
}

This allows efficient traversal and slicing of large text structures.

๐Ÿ“„ License #

MIT. Based on concepts in Zed's Rope & SumTree.


1
likes
0
points
43
downloads

Publisher

verified publisheriamngoni.co.zw

Weekly Downloads

A fast, immutable rope data structure in Dart using a SumTree architecture. Inspired by Zed's implementation, this rope is optimized for large-scale string manipulation and editor-like use cases.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on rope