pub struct List { /* private fields */ }Expand description
A list: a finite sequence, in order.
Implementations§
Source§impl List
impl List
Sourcepub fn parts(&self) -> ListParts<'_>
pub fn parts(&self) -> ListParts<'_>
Returns what the list is made of: the list is front, then the
elements of tree it takes, then back.
The front and the back hold at most eight elements each. A list of more than eight whose ends do not hold all of it has a tree, and one of at most eight has none and holds everything at its back.
Sourcepub fn tree(&self) -> Option<Node>
pub fn tree(&self) -> Option<Node>
Returns the whole list as one balanced tree, or None when it is
empty: its front, the elements it takes from its tree and its back,
joined. The tree shares every node of the list’s own that the cut
and the joins do not pass through, so it costs O(log n) new nodes.
Sourcepub fn from_parts(
front: Vec<Value>,
tree: Option<(Node, usize, usize)>,
back: Vec<Value>,
) -> Result<List, StructureError>
pub fn from_parts( front: Vec<Value>, tree: Option<(Node, usize, usize)>, back: Vec<Value>, ) -> Result<List, StructureError>
Returns the list of front, then the taken elements of tree
that follow its first skip, then back, sharing tree.
The list’s measure is that of its ends and of the window, which the tree’s nodes record, so this costs O(EDGE + log n) whatever the tree holds, but for a list of at most eight elements, which keeps no tree and is copied out of it.
§Errors
StructureError::End when an end holds more than eight elements,
and StructureError::Window when the tree does not hold
skip + taken elements.
Sourcepub fn get(&self, index: usize) -> Option<&Value>
pub fn get(&self, index: usize) -> Option<&Value>
Returns the element at a zero-based position.
Sourcepub fn get_int(&self, index: &Int) -> Option<&Value>
pub fn get_int(&self, index: &Int) -> Option<&Value>
Returns the element at a zero-based Int position: None for a
negative one or one not less than the length (list.get).
Sourcepub fn iter(
&self,
) -> impl DoubleEndedIterator<Item = &Value> + ExactSizeIterator
pub fn iter( &self, ) -> impl DoubleEndedIterator<Item = &Value> + ExactSizeIterator
Returns the elements, in order.
Sourcepub fn slice(&self, start: usize, end: usize) -> Option<List>
pub fn slice(&self, start: usize, end: usize) -> Option<List>
Returns the elements from start up to, not including, end, sharing
this list’s tree, or None unless start ≤ end ≤ length.
Sourcepub fn push_front(self, item: Value) -> List
pub fn push_front(self, item: Value) -> List
Returns self with item added at the front.