Struct Node

Source
pub struct Node<'a, N>
where N: 'a,
{ /* private fields */ }
Expand description

Represents a borrowed node in the Eytzinger tree. This node may be used to navigate to parent or child nodes.

Implementations§

Source§

impl<'a, N> Node<'a, N>

Source

pub fn tree(&self) -> &'a EytzingerTree<N>

Gets the Eytzinger tree this node is for.

§Examples
use lz_eytzinger_tree::{EytzingerTree, Node};

let tree = {
    let mut tree = EytzingerTree::<u32>::new(8);
    tree.set_root_value(5);
    tree
};

let root = tree.root().unwrap();
assert_eq!(root.tree(), &tree);
Source

pub fn value(&self) -> &'a N

Gets the value stored at this node.

§Examples
use lz_eytzinger_tree::{EytzingerTree, Node};

let tree = {
    let mut tree = EytzingerTree::<u32>::new(8);
    tree.set_root_value(5);
    tree
};

let root = tree.root().unwrap();
assert_eq!(root.value(), &5);
Source

pub fn parent(&self) -> Option<Node<'a, N>>

Gets the parent of this node or None is there was none.

§Examples
use lz_eytzinger_tree::{EytzingerTree, Node};

let tree = {
    let mut tree = EytzingerTree::<u32>::new(8);
    {
        let mut root = tree.set_root_value(5);
        root.set_child_value(2, 3);
    }
    tree
};

let root = tree.root().unwrap();
let child = root.child(2).unwrap();
assert_eq!(child.parent(), Some(root));
Source

pub fn child(&self, index: usize) -> Option<Node<'a, N>>

Gets the child of this node at the specified index or None if there wasn’t one.

§Examples
use lz_eytzinger_tree::{EytzingerTree, Node};

let tree = {
    let mut tree = EytzingerTree::<u32>::new(8);
    {
        let mut root = tree.set_root_value(5);
        root.set_child_value(2, 3);
    }
    tree
};

let root = tree.root().unwrap();
let child = root.child(2).unwrap();
assert_eq!(child.value(), &3);
Source

pub fn child_iter(&self) -> NodeChildIter<'a, N>

Gets an iterator over the immediate children of this node. This only includes children for which there is a node.

§Examples
use lz_eytzinger_tree::{EytzingerTree, Node};

let tree = {
    let mut tree = EytzingerTree::<u32>::new(8);
    {
        let mut root = tree.set_root_value(5);
        root.set_child_value(0, 1);
        root.set_child_value(2, 3);

    }
    tree
};

let root = tree.root().unwrap();
let child_values: Vec<_> = root.child_iter().map(|n| n.value()).collect();
assert_eq!(child_values, vec![&1, &3]);
Source

pub fn depth_first_iter(&self, order: DepthFirstOrder) -> DepthFirstIter<'a, N>

Gets a depth-first iterator over this and all child nodes.

Source

pub fn breadth_first_iter(&self) -> BreadthFirstIter<'a, N>

Gets a breadth-first iterator over this and all child nodes.

Trait Implementations§

Source§

impl<'a, N> Clone for Node<'a, N>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, N> Debug for Node<'a, N>
where N: 'a + Debug,

Source§

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

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

impl<'a, N> Deref for Node<'a, N>

Source§

type Target = N

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'a, N> From<&'a NodeMut<'a, N>> for Node<'a, N>

Source§

fn from(value: &'a NodeMut<'a, N>) -> Node<'a, N>

Converts to this type from the input type.
Source§

impl<'a, N> From<NodeMut<'a, N>> for Node<'a, N>

Source§

fn from(value: NodeMut<'a, N>) -> Node<'a, N>

Converts to this type from the input type.
Source§

impl<'a, N> Hash for Node<'a, N>
where N: 'a + Hash,

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a, N> PartialEq for Node<'a, N>
where N: 'a + PartialEq,

Source§

fn eq(&self, other: &Node<'a, N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, N> Copy for Node<'a, N>

Source§

impl<'a, N> Eq for Node<'a, N>
where N: 'a + Eq,

Source§

impl<'a, N> StructuralPartialEq for Node<'a, N>
where N: 'a,

Auto Trait Implementations§

§

impl<'a, N> Freeze for Node<'a, N>

§

impl<'a, N> RefUnwindSafe for Node<'a, N>
where N: RefUnwindSafe,

§

impl<'a, N> Send for Node<'a, N>
where N: Sync,

§

impl<'a, N> Sync for Node<'a, N>
where N: Sync,

§

impl<'a, N> Unpin for Node<'a, N>

§

impl<'a, N> UnwindSafe for Node<'a, N>
where N: RefUnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.