Skip to main content

TreeView

Struct TreeView 

Source
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 RemovedValues

Implementations§

Source§

impl<'tree, T> TreeView<'tree, T>

Source

pub fn new( offset: &'tree [u16], layout: &'tree mut Nodes, values: &'tree mut TreeValues<T>, removed_values: &'tree mut RemovedValues, ) -> Self

Source

pub fn view(&mut self) -> TreeView<'_, T>

Source

pub fn get_mut(&mut self, value_id: ValueId) -> Option<&mut T>

Get a mutable reference by value id

Source

pub fn get(&self, value_id: ValueId) -> Option<&T>

Get a reference by value id

Source

pub fn contains(&self, key: ValueId) -> bool

Source

pub fn layout_len(&self) -> usize

The number of children (not counting childrens children)

Source

pub fn for_each<F, U>(&mut self, f: F) -> Option<U>
where F: FnMut(&[u16], &mut T, TreeView<'_, T>) -> ControlFlow<U>,

Source

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.

Source

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.

Source

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);
Source

pub fn truncate_children<F>(&mut self, f: &mut F)
where F: FnMut(T),

Remove all the nodes in this view

Source

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.

Source

pub fn with_value_mut<F, V>(&mut self, value_id: ValueId, f: F) -> Option<V>
where F: FnOnce(&[u16], &mut T, TreeView<'_, T>) -> 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

Source

pub fn nodes_and_values(&self) -> (&[Node], &TreeValues<T>)

Trait Implementations§

Source§

impl<'tree, T: Debug> Debug for TreeView<'tree, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'tree, T> !UnwindSafe for TreeView<'tree, T>

§

impl<'tree, T> Freeze for TreeView<'tree, T>

§

impl<'tree, T> RefUnwindSafe for TreeView<'tree, T>
where T: RefUnwindSafe,

§

impl<'tree, T> Send for TreeView<'tree, T>
where T: Send,

§

impl<'tree, T> Sync for TreeView<'tree, T>
where T: Sync,

§

impl<'tree, T> Unpin for TreeView<'tree, T>

§

impl<'tree, T> UnsafeUnpin for TreeView<'tree, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.