百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

crop

> 开发工具
开源

一个相当快的文本绳子

320 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一个相当快的文本绳子

crop

crop is an implementation of a text rope, a data structure designed to be used in applications that need to handle frequent edits to arbitrarily large buffers, such as text editors.

crop's Rope is backed by a B-tree, ensuring that the time complexity of inserting, deleting or replacing a piece of text is always logarithmic in the size of the Rope.

crop places an extreme focus on performance: check out the benchmarks to see how it stacks up against similar projects.

Built with parallelism in mind

Ropes use thread-safe reference counting to share data between threads. Cloning a Rope takes up only 16 extra bytes of memory, and its copy-on-write semantics allow the actual text contents to be cloned incrementally as different clones diverge due to user edits.

This allows to cheaply snapshot a Rope and send it to a background thread to perform any IO or CPU-intensive computations, while the main thread is kept responsive and always ready for the next batch of edits.

Example usage

…

Check out the docs for a more in-depth overview of the crate.

Comparison with other ropes

As of April 2023 there are (to my knowledge) 3 rope crates that are still actively maintained: crop, Jumprope and Ropey. The following is a quick (and incomplete) overview of their features and tradeoffs to help you decide which one is best suited for your specific use case.

Speed

The following results were obtained by running the real world, character-by-character editing traces provided by crdt-benchmarks on a 2018 MacBook Pro with an Intel Core i7.

Dataset crop (ms) Jumprope (ms) Ropey (ms) std::string::String (ms)
automerge-paper 12.39 12.52 44.14 108.57
rustcode 2.67 2.86 7.96 13.40
sveltecomponent 0.95 1.08 3.65 1.22
seph-blog1 6.47 6.94 23.46 22.26

Cheap clones

Both crop and Ropey allow their Ropes to be cloned in O(1) in time and space by sharing data between clones, whereas cloning a JumpRope involves re-allocating the actual text contents, just like it would with a regular String.

Indexing metric

Jumprope and Ropey both use Unicode codepoint offsets (chars in Rust) as their primary indexing metric. crop uses UTF-8 code unit (aka byte) offsets, just like Rust's Strings.

Line breaks

Both crop and Ropey track line breaks, allowing you to convert between line and byte offsets and to iterate over the lines of their Ropes and RopeSlices. Ropey can be configured to recognize all Unicode line breaks, while crop only recognizes LF and CRLF as line terminators.

Jumprope doesn't currently have any line-based APIs.

Acknowledgements

  • A significant portion of crop's public API was inspired by the excellent Ropey crate (from which I also borrowed some test vectors). Unlike crop, Ropey uses code points (chars in Rust-speak) as its primary indexing metric. If you'd prefer to work with char offsets rather than byte offsets Ropey might be a great alternative;

  • Even though the implementations are quite different, crop's Metric trait was inspired by the homonymous trait in xi_rope. Check out the second blog post in the "Rope science" series by Raph Levien for more infos.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rustdata-structuresropestext-editingtext-editors

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类开发工具
定价开源

> 相关工具

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具