by agumonkey · 9y ago · 0 comments
https://github.com/josephg/librope
It could happily do 5M random single character edits / second on my old laptop. Its wild what you can pull off with C. Much more memory efficient too (it uses about 4 pointers of overhead per 180 characters).
I'd love to see a version which supported traversal using more methods though - that library needs to support searching by line as well as character count.
I tried porting it to Rust a few times but unfortunately couldn't figure out how to port it without introducing indirection everywhere. Modern 'C replacement' languages don't let you do the same funky memory management tricks. (Like using a dynamically sized array at the end of a struct allocated in the same block.)
Each item in the skip list has an associated randomly sized list of next pointers. In C I store that list at the end of the node data structure, and dynamically allocate the struct based on how much memory I need (basically, size of static array of characters + size of dynamic nexts array). In Rust in theory I can make my struct unsized to do the same thing. (Well, it pushes the nexts height out into the pointer but that's not too bad). But there doesn't seem to be any syntax to initialise the values in my unsized struct array itself once I've allocated it - even in unsafe.
If you can figure out simply how to initialize a custom heap-allocated unsized struct I'll happily keep working on it. My conclusion at the time (and, still, after trying out tokio) is that rust isn't mature enough to replace C yet.
This is a rope implementation in Rust with lots of features useful for text editors.
Super easy to implement and gets you a long way. I am a little surprised that it has not come up yet on a thread on editor implementations.
In fact the author of the blog post talks about it in his very next post. Here's his lede
Last week, I promised to continue my discussion of ropes.
I’m going to break that promise. But it’s in a good cause.
http://scienceblogs.com/goodmath/2009/02/18/gap-buffers-or-w...