Next: Concatenation, Previous: Conversion procedures, Up: rope API [Contents][Index]
If rope is unbalanced, returns a balanced rope, otherwise does
nothing and returns rope itself. This procedure will not only
reallocate the nodes themselves (by necessity since the data structure
is immutable) but it may also reallocate the strings involved by
attempting to defragment them, so it will concatenate small strings to
bring their size closer to *rope-maximum-leaf-size*. It will not
go in the other direction and attempt to split long leaf strings
however. Long strings can only be found in a rope if the user of the
API has explicitly put them there. Note that a rope may be highly
fragmented but not considered unbalanced according to
rope-balanced?.
One can force the rebalancing (and defragmentation) of a rope even if it is already balanced by using:
(define r …) (rope-ec (:rope s r) s)
Example 2.6: Forcing the rebalancing of a rope.