Next: rope transpose API, Previous: Eager comprehensions, Up: rope API [Contents][Index]
The maximum leaf size threshold (default: ‘1024’). This is a
parameter (see Parameters in The Guile Reference
Manual) that when set will be respected by most future rope operations.
The rope constructor itself does not respect it however.
See Balancing a rope for the details of the necessity of such a
threshold.
For example, here is how it affects rope rebalancing:
(parameterize ((*rope-maximum-leaf-size* 1))
(rope->cons (rope-balance "wow!")))
⇒ (("w" . "o") "w" . "!")
Example 2.18: Setting the maximum leaf size to a small value affects rebalancing.
Note that in the above example we have set the leaf size to ‘1’, and the rebalancing of the string ‘wow!’ becomes a rope with four leaves. Now let us go in the opposite direction:
(define r (cons->rope '(("w" . "o") "w" . "!")))
(rope-ec (:rope s r) r)
⇒ "wow!"
Example 2.19: Forcing a balanced by fragmented rope to be rebalanced to defragment it.
In the above example, we recover the original string since it fits in a
single string of the default maximum leaf size. We did not use
rope-balance because the rope is considered balanced and the
procedure would have no effect. Instead, we forced the rebalancing of
the rope as in Example 2.6.
Finally let us demonstrate that the rope constructor itself is
not affected by the maximum leaf size threshold, as we trust that the
user of the API has passed correct data to the constructor:
(parameterize ((*rope-maximum-leaf-size* 1)) (rope "hello" "world")) ⇒ #<<rope> left: "hello" right: "world" length: 10 depth: 1>
Example 2.20: The rope constructor does not respect the max leaf
size.
Next: rope transpose API, Previous: Eager comprehensions, Up: rope API [Contents][Index]