pub struct Node<T: Element = Value>(/* private fields */);Expand description
A shared node of a tree: a whole tree, or a part of one.
Cloning one shares it, and two handles to one node have one
Node::id. A list’s or a dictionary’s tree is made of nodes, which the
lists and dictionaries made from it share: List::parts and
Dict::root read the nodes a value is made of, Node::shape what
each node holds, and Node::leaf and Node::branch build a tree
again, node by node, so that what was shared stays shared.
Implementations§
Source§impl<T: Element> Node<T>
impl<T: Element> Node<T>
Sourcepub fn leaf(items: Vec<T>) -> Result<Self, StructureError>
pub fn leaf(items: Vec<T>) -> Result<Self, StructureError>
Returns the leaf holding items.
§Errors
StructureError::Leaf unless they number from one to as many as a
leaf of their kind holds.
Sourcepub fn branch(left: Self, right: Self) -> Self
pub fn branch(left: Self, right: Self) -> Self
Returns the tree holding left’s elements, then right’s.
When the two are as high as each other or within one level, which
they are whenever this crate made the tree being rebuilt, this is one
new branch over exactly left and right, so each stays shared.
Every tree here is balanced (AVL), and indexing, insertion, removal,
joining and cutting rely on that for their cost; so when the two
differ by more, as a tree from another writer may, the lower is
joined into the higher’s near spine and the branches on that path
are rebuilt balanced, in O(difference in height). Every node below
that path stays shared, and the elements and their order are the
same either way.
Sourcepub fn id(&self) -> usize
pub fn id(&self) -> usize
Returns what tells this node apart from every other node alive: two handles answer alike exactly when they share one node. The answer means something only while a handle to the node is kept, since a node made after this one is dropped may answer the same.
Sourcepub fn window(&self, skip: usize, count: usize) -> Result<Self, StructureError>
pub fn window(&self, skip: usize, count: usize) -> Result<Self, StructureError>
Returns the tree of the count elements that follow this tree’s
first skip, sharing every node the cut does not pass through.
§Errors
StructureError::Window unless count is at least one and the
tree holds skip + count elements.