Tree

Struct Tree 

Source
pub struct Tree<C: Cookie, I: NodeIndex, O: OptionalNodeIndex<I>, K: NodeKey<C, I>, N> { /* private fields */ }
Expand description

A vector-backed tree where you can store nodes

Implementations§

Source§

impl<C: Cookie, I: NodeIndex, O: OptionalNodeIndex<I>, K: NodeKey<C, I>, N> Tree<C, I, O, K, N>

Source

pub fn new() -> Self

Source

pub fn node_key(&self, index: I) -> K

Source

pub fn get(&self, key: K) -> Option<&N>

Source

pub fn get_mut(&mut self, key: K) -> Option<&mut N>

Source§

impl<C: Cookie, I: NodeIndex, O: OptionalNodeIndex<I>, K: NodeKey<C, I>, N: Default> Tree<C, I, O, K, N>

Source

pub fn create(&mut self) -> K

Allocate a node in the internal vector

Source

pub fn delete_children(&mut self, key: K)

Remove the children of a node from the tree

Internal references to the nodes are removed (links with siblings & parent). This function behaves recursively to remove nodes from leaf to branch.

Source

pub fn delete(&mut self, key: K)

Remove a node and its children from the tree

Internal references to the node are removed (links with siblings & parent). This function behaves recursively to remove nodes from leaf to branch.

Source

pub fn reset(&mut self, key: K)

Removes the children of a node and reset its public properties to their defaults

Source

pub fn insert_after(&mut self, prev: K, key: K)

Insert a node as the next sibling of prev

Source

pub fn append_children(&mut self, key: K, parent: K)

Adds one or multiple “children” nodes to a “parent” node

node and all it’s siblings are appended to the list of children of parent.

Source

pub fn replace(&mut self, old: K, new: K)

Change references to old so that they point to new instead and remove old

Source

pub fn detach_children(&mut self, parent: K) -> Option<K>

Detach a node from all its “children”, leaving them “orphans”

If the node had no children, None is returned.

Source

pub fn child_index(&self, key: K) -> Option<usize>

Get the index of this node relative to its parent’s children

Source

pub fn parent(&self, key: K) -> Option<K>

Locate the parent of a node

Source

pub fn first_child(&self, key: K) -> Option<K>

Locate the first child of a node

Source

pub fn last_child(&self, key: K) -> Option<K>

Locate the last child of a node

Source

pub fn prev_sibling(&self, key: K) -> K

Locate the previous sibling of a node

Note: siblings are looping, meaning that calling this for the first child of a node will locate the last child of the node.

Source

pub fn next_sibling(&self, key: K) -> K

Locate the next sibling of a node

Note: siblings are looping, meaning that calling this for the last child of a node will locate the first child of the node.

Source

pub fn is_only_child(&self, key: K) -> bool

Returns true if node has no sibling except itself

Trait Implementations§

Source§

impl<C: Cookie, I: NodeIndex, O: OptionalNodeIndex<I>, K: NodeKey<C, I>, N: Default + Debug> Debug for Tree<C, I, O, K, N>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<C: Cookie, I: NodeIndex, O: OptionalNodeIndex<I>, K: NodeKey<C, I>, N> Index<K> for Tree<C, I, O, K, N>

Source§

type Output = N

The returned type after indexing.
Source§

fn index(&self, key: K) -> &N

Performs the indexing (container[index]) operation. Read more
Source§

impl<C: Cookie, I: NodeIndex, O: OptionalNodeIndex<I>, K: NodeKey<C, I>, N> IndexMut<K> for Tree<C, I, O, K, N>

Source§

fn index_mut(&mut self, key: K) -> &mut N

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<C, I, O, K, N> Freeze for Tree<C, I, O, K, N>
where C: Freeze, O: Freeze,

§

impl<C, I, O, K, N> RefUnwindSafe for Tree<C, I, O, K, N>

§

impl<C, I, O, K, N> Send for Tree<C, I, O, K, N>
where C: Send, O: Send, K: Send, N: Send, I: Send,

§

impl<C, I, O, K, N> Sync for Tree<C, I, O, K, N>
where C: Sync, O: Sync, K: Sync, N: Sync, I: Sync,

§

impl<C, I, O, K, N> Unpin for Tree<C, I, O, K, N>
where C: Unpin, O: Unpin, K: Unpin, N: Unpin, I: Unpin,

§

impl<C, I, O, K, N> UnwindSafe for Tree<C, I, O, K, N>

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.