hint_max_leaf_char_len
- The maximal number of chars that should be permitted in a single nodehint_max_node_height
- The maximal height that should be permitted in a tree.concat
- A node obtained from the concatenation of two other nodesleaf
- A text component in a rope.node
root
- Implementation of type rope
bal
- Balance a node.byte_len
char_at
- # Argumentschar_len
cmp
concat2
flatten
- Replace a subtree by a single leaf with the same contents.height
loop_chars
loop_leaves
- Loop through a node, leaf by leafof_str
- Adopt a string as a node.of_substr
- Adopt a slice of a string as a node.of_substr_unsafer
- Adopt a slice of a string as a node.serialize_node
sub_bytes
- Compute the subnode of a node.sub_chars
- Compute the subnode of a node.tree_from_forest_destructive
- Concatenate a forest of nodes into one tree.rope::node::char_iterator
rope::node::leaf_iterator
hint_max_leaf_char_len
uint
The maximal number of chars that should be permitted in a single node
This is not a strict value
hint_max_node_height
uint
The maximal height that should be permitted in a tree.
This is not a strict value
concat
type concat = {left: @node, right: @node, char_len: uint, byte_len: uint, height: uint,}
A node obtained from the concatenation of two other nodes
byte_len - The number of bytes in the subrope.
Used to pre-allocate the correct amount of storage for serialization.
height - Height of the subrope.
Used for rebalancing and to allocate stacks for traversals.
leaf
type leaf = {byte_offset: uint, byte_len: uint, char_len: uint, content: @str,}
A text component in a rope.
This is actually a slice in a rope, so as to ensure maximal sharing.
content
content
to usecontent - Contents of the leaf.
Note that we can have char_len < str::char_len(content)
, if this leaf is only a subset of the string. Also note that the string can be shared between several ropes, e.g. for indexing purposes.
node
leaf(leaf)
- A leaf consisting in a str
concat(concat)
- The concatenation of two ropesroot
Implementation of type rope
empty
- An empty ropecontent(@node)
- A non-empty ropebal
fn bal(node: @node) -> option<@node>
Balance a node.
hint_max_node_height
, do nothingoption::none
if no transformation happenedoption::some(x)
otherwise, in which case x
has the same contents as node
bot lower height and/or fragmentation.byte_len
pure fn byte_len(node: @node) -> uint
char_at
fn char_at(node: @node, pos: uint) -> char
The character at position pos
The function will fail if pos
is not a valid position in the rope.
Performance note: This function executes in a time proportional to the height of the rope + the (bounded) length of the largest leaf.
char_len
pure fn char_len(node: @node) -> uint
cmp
fn cmp(a: @node, b: @node) -> int
concat2
fn concat2(left: @node, right: @node) -> @node
flatten
fn flatten(node: @node) -> @node
Replace a subtree by a single leaf with the same contents.
This function executes in linear time.
height
fn height(node: @node) -> uint
loop_chars
fn loop_chars(node: @node, it: fn(char) -> bool) -> bool
loop_leaves
fn loop_leaves(node: @node, it: fn(leaf) -> bool) -> bool
Loop through a node, leaf by leaf
true
to continue, false
to stoptrue
If execution proceeded correctly, false
if it was interrupted, that is if it
returned false
at any point.
of_str
fn of_str(str: @str) -> @node
Adopt a string as a node.
If the string is longer than max_leaf_char_len
, it is logically split between as many leaves as necessary. Regardless, the string itself is not copied.
Performance note: The complexity of this function is linear in the length of str
.
of_substr
fn of_substr(str: @str, byte_start: uint, byte_len: uint) -> @node
Adopt a slice of a string as a node.
If the slice is longer than max_leaf_char_len
, it is logically split between as many leaves as necessary. Regardless, the string itself is not copied
str
starts.str
to use.Behavior is undefined if byte_start
or byte_len
do not represent valid positions in str
of_substr_unsafer
fn of_substr_unsafer(str: @str, byte_start: uint, byte_len: uint,
char_len: uint) -> @node
Adopt a slice of a string as a node.
If the slice is longer than max_leaf_char_len
, it is logically split between as many leaves as necessary. Regardless, the string itself is not copied
str
starts.str
to use.str
in the interval [byte_start, byte_start+byte_len)byte_start
or byte_len
do not represent valid positions in str
char_len
does not accurately represent the number of chars between byte_start and byte_start+byte_lenserialize_node
fn serialize_node(node: @node) -> str
sub_bytes
fn sub_bytes(node: @node, byte_offset: uint, byte_len: uint) -> @node
Compute the subnode of a node.
node
node
This function fails if byte_offset
or byte_len
do not represent valid positions in node
.
sub_chars
fn sub_chars(node: @node, char_offset: uint, char_len: uint) -> @node
Compute the subnode of a node.
node
node
This function fails if char_offset
or char_len
do not represent valid positions in node
.
tree_from_forest_destructive
fn tree_from_forest_destructive(forest: ~[mut @node]) -> @node
Concatenate a forest of nodes into one tree.