an-cabal / an-rope

an rope data structure
https://docs.rs/an-rope
MIT License
11 stars 2 forks source link

Consider chunking the string in `Rope::from(String)` #32

Closed hawkw closed 7 years ago

hawkw commented 7 years ago

Currently, when we create a new Rope from a String, we put the whole string in one Leaf node. That means that indexing-based operations will initially have roughly the same time overhead as indexing a String, and we won't see performance improvements until the Rope has been appended or inserted into enough to turn it into a nice tree structure. We might want to consider having the Rope::from<String> implementation split the string into chunks so that we can reap Rope performance benefits immediately.

hawkw commented 7 years ago

One way to do this that springs initially to mind is to create an unbalanced branch as the root node, rather than a leaf, and then call .rebalance() on it. If we were to, say, put the whole string in the left child of a branch and then rebalance that node immediately, we'd end up with a nice, balanced tree using our already existing .rebalance() method.

Of course, this may not be the best way to do this, but it was the obvious way, to me.

hawkw commented 7 years ago

@cjm00, what do you think?