pub struct TreeView<'tree, T> {
pub offset: &'tree [u16],
pub values: &'tree mut TreeValues<T>,
pub layout: &'tree mut Nodes,
pub removed_values: &'tree mut RemovedValues,
}Fields§
§offset: &'tree [u16]§values: &'tree mut TreeValues<T>§layout: &'tree mut Nodes§removed_values: &'tree mut RemovedValuesImplementations§
Source§impl<'tree, T> TreeView<'tree, T>
impl<'tree, T> TreeView<'tree, T>
pub fn new( offset: &'tree [u16], layout: &'tree mut Nodes, values: &'tree mut TreeValues<T>, removed_values: &'tree mut RemovedValues, ) -> Self
pub fn view(&mut self) -> TreeView<'_, T>
Sourcepub fn get_mut(&mut self, value_id: ValueId) -> Option<&mut T>
pub fn get_mut(&mut self, value_id: ValueId) -> Option<&mut T>
Get a mutable reference by value id
pub fn contains(&self, key: ValueId) -> bool
Sourcepub fn layout_len(&self) -> usize
pub fn layout_len(&self) -> usize
The number of children (not counting childrens children)
pub fn for_each<F, U>(&mut self, f: F) -> Option<U>
Sourcepub fn path(&self, id: impl Into<ValueId>) -> Box<[u16]>
pub fn path(&self, id: impl Into<ValueId>) -> Box<[u16]>
The path to a value in the tree.
Unlike a ValueId which will never change for a given value,
the NodePath can change if the node is moved to another location within the tree.
§Panics
Panics if the value id is no long present in the tree.
Sourcepub fn get_node_and_value(&self, path: &[u16]) -> Option<(ValueId, &T)>
pub fn get_node_and_value(&self, path: &[u16]) -> Option<(ValueId, &T)>
Get a reference to the value and the value id This has an additional cost since the value id has to be found first.
Sourcepub fn insert<'a>(
&'a mut self,
parent: &'a [u16],
) -> InsertTransaction<'a, 'tree, T>
pub fn insert<'a>( &'a mut self, parent: &'a [u16], ) -> InsertTransaction<'a, 'tree, T>
Being an insert transaction. The transaction has to be committed before the value is written to the tree.
let mut tree = Tree::empty();
let mut tree = tree.view();
let transaction = tree.insert(&[]);
let value_id = transaction.commit_child(1usize).unwrap();
let one = tree.get_mut(value_id).unwrap();
assert_eq!(*one, 1);Sourcepub fn truncate_children<F>(&mut self, f: &mut F)where
F: FnMut(T),
pub fn truncate_children<F>(&mut self, f: &mut F)where
F: FnMut(T),
Remove all the nodes in this view
Sourcepub fn relative_remove<F>(&mut self, path: &[u16], f: &mut F)where
F: FnMut(T),
pub fn relative_remove<F>(&mut self, path: &[u16], f: &mut F)where
F: FnMut(T),
Remove a Node and value from the tree.
This will also remove all the children and associated values.
Sourcepub fn with_value_mut<F, V>(&mut self, value_id: ValueId, f: F) -> Option<V>
pub fn with_value_mut<F, V>(&mut self, value_id: ValueId, f: F) -> Option<V>
Perform a given operation (F) on a mutable reference to a value in the tree
while still having mutable access to the rest of the tree.
§Panics
This will panic if the value is already checked out