Struct ropey::Rope
[−]
[src]
pub struct Rope { /* fields omitted */ }
A rope data structure for storing text in a format that is efficient for insertion and removal even for extremely large strings.
Methods
impl Rope
[src]
fn new() -> Rope
Creates a new empty rope
fn from_str(s: &str) -> Rope
Creates a new rope from a string slice
fn from_string(s: String) -> Rope
Creates a new rope from a string, consuming the string
fn char_count(&self) -> usize
fn grapheme_count(&self) -> usize
fn line_ending_count(&self) -> usize
fn grapheme_count_in_char_range(&self, pos_a: usize, pos_b: usize) -> usize
Returns the number of graphemes between char indices pos_a and pos_b. This is not as simple as a subtraction of char_index_to_grapheme_index() calls, because the char indices may split graphemes. Runs in O(log N) time.
fn char_index_to_grapheme_index(&self, pos: usize) -> usize
Returns the index of the grapheme that the given char index is a part of.
fn grapheme_index_to_char_index(&self, pos: usize) -> usize
Returns the beginning char index of the given grapheme index.
fn char_index_to_line_index(&self, pos: usize) -> usize
Returns the index of the line that the given char index is on.
fn line_index_to_char_index(&self, li: usize) -> usize
Returns the char index at the start of the given line index.
fn char_at_index(&self, index: usize) -> char
fn grapheme_at_index<'a>(&'a self, index: usize) -> &'a str
fn insert_text_at_char_index(&mut self, text: &str, pos: usize)
Inserts the given text at the given char index. For small lengths of 'text' runs in O(log N) time. For large lengths of 'text', dunno. But it seems to perform sub-linearly, at least.
fn remove_text_between_char_indices(&mut self, pos_a: usize, pos_b: usize)
Removes the text between the given char indices. For small distances between pos_a and pos_b runs in O(log N) time. For large distances, dunno. If it becomes a performance bottleneck, can special-case that to two splits and an append, which are all sublinear.
fn split_at_char_index(&mut self, pos: usize) -> Rope
Splits a rope into two pieces from the given char index. The first piece remains in this rope, the second piece is returned as a new rope. I think this runs in O(log N) time, but this needs more analysis to be sure. It is at least sublinear.
fn append(&mut self, rope: Rope)
Appends another rope to the end of this one, consuming the other rope. Runs in O(log N) time.
fn to_string(&self) -> String
Makes a copy of the rope as a string. Runs in O(N) time.
fn chunk_iter<'a>(&'a self) -> RopeChunkIter<'a>
Creates a chunk iterator for the rope
fn chunk_iter_at_char_index<'a>(
&'a self,
index: usize
) -> (usize, RopeChunkIter<'a>)
&'a self,
index: usize
) -> (usize, RopeChunkIter<'a>)
Creates a chunk iter starting at the chunk containing the given char index. Returns the chunk iter and its starting char index.
fn char_iter<'a>(&'a self) -> RopeCharIter<'a>
Creates an iterator at the first char of the rope
fn char_iter_at_index<'a>(&'a self, index: usize) -> RopeCharIter<'a>
Creates an iterator starting at the given char index
fn char_iter_between_indices<'a>(
&'a self,
pos_a: usize,
pos_b: usize
) -> RopeCharIter<'a>
&'a self,
pos_a: usize,
pos_b: usize
) -> RopeCharIter<'a>
Creates an iterator that starts at pos_a and stops just before pos_b.
fn grapheme_iter<'a>(&'a self) -> RopeGraphemeIter<'a>
Creates an iterator at the first grapheme of the rope
fn grapheme_iter_at_index<'a>(&'a self, index: usize) -> RopeGraphemeIter<'a>
Creates an iterator at the given grapheme index
fn grapheme_iter_between_indices<'a>(
&'a self,
pos_a: usize,
pos_b: usize
) -> RopeGraphemeIter<'a>
&'a self,
pos_a: usize,
pos_b: usize
) -> RopeGraphemeIter<'a>
Creates an iterator that starts a pos_a and stops just before pos_b.
fn line_iter<'a>(&'a self) -> RopeLineIter<'a>
Creates an iterator over the lines in the rope.
fn line_iter_at_index<'a>(&'a self, index: usize) -> RopeLineIter<'a>
Creates an iterator over the lines in the rope, starting at the given line index.