Yomguithereal / mnemonist

Curated collection of data structures for the JavaScript/TypeScript language.
https://yomguithereal.github.io/mnemonist
MIT License
2.25k stars 92 forks source link

Roadmap #15

Open Yomguithereal opened 7 years ago

Yomguithereal commented 7 years ago
vmasto commented 7 years ago

How about a Rope? I will try to find time to implement one if you're ok with it.

Yomguithereal commented 7 years ago

Sure @vmasto. Why not. I just have one concern: how do most JavaScript engines implement their strings. The problem is that the native string is probably optimized to do what a rope can do and will probably do it better. But this is just an intuition I have, this is not backed by any benchmark. However, if your rope is able to support sequences of arbitrary elements (not just a string of characters but, say, a list of words) then yes, it would probably be useful. What do you think?

vmasto commented 7 years ago

I am under the impression that native strings have O(n) complexities when it comes to insert, delete and concat whereas a Rope would give us O(m) (where m is the substring's length to be inserted/del/concat) with the caveat that we'll lose random access in constant time. Thus a Rope would be suitable for frequent text manipulation (e.g. a text editor?).

It's a good point though and I'll have to verify what I'm saying here since string implementation changes from engine to engine. I'll get back to you on this.

Another concern is that rope implementations most probably already exist around and maybe it'd be of more value to contribute with a more exotic data structure, although my experience is limited on those.