Struct darkfi_sdk::dark_tree::DarkTree
source · pub struct DarkTree<T: Clone + Send + Sync> {
leaf: DarkTreeLeaf<T>,
children: Vec<DarkTree<T>>,
min_capacity: usize,
max_capacity: Option<usize>,
}
Expand description
This struct represents a DFS post-order traversal Tree.
When we iterate through the tree, we first process tree node’s children, and then the node itself, recursively. Based on this, initial tree node (leaf), known as the root, will always show up at the end of iteration. It is advised to always execute .build() after finishing setting up the Tree, to properly index it and check its integrity.
Fields§
§leaf: DarkTreeLeaf<T>
This tree’s leaf information, along with its data
children: Vec<DarkTree<T>>
Vector containing all tree’s branches(children tree)
min_capacity: usize
Min capacity of the tree, including all children nodes recursively from the root. Since root is always present, min capacity must always be >= 1. This is enforced by the root, so children nodes don’t have to set it up. If children nodes children(recursively) make us not exceed that min capacity, we will be able to catch it using .check_min_capacity() or .integrity_check().
max_capacity: Option<usize>
Optional max capacity of the tree, including all children nodes recursively from the root. None indicates no capacity restrictions. This is enforced by the root, so children nodes don’t have to set it up. If children nodes children(recursively) make us exceed that capacity, we will be able to catch it using .check_max_capacity() or .integrity_check().
Implementations§
source§impl<T: Clone + Send + Sync> DarkTree<T>
impl<T: Clone + Send + Sync> DarkTree<T>
sourcepub fn new(
data: T,
children: Vec<DarkTree<T>>,
min_capacity: Option<usize>,
max_capacity: Option<usize>,
) -> DarkTree<T>
pub fn new( data: T, children: Vec<DarkTree<T>>, min_capacity: Option<usize>, max_capacity: Option<usize>, ) -> DarkTree<T>
Initialize a DarkTree
, using provided data to
generate its root.
sourcepub fn build(&mut self) -> DarkTreeResult<()>
pub fn build(&mut self) -> DarkTreeResult<()>
Build the DarkTree
indexes and perform an
integrity check on them. This should be used
after we have appended all child nodes, so we
don’t have to call .index() and .integrity_check()
manually.
sourcepub fn build_vec(&mut self) -> DarkTreeResult<Vec<DarkLeaf<T>>>
pub fn build_vec(&mut self) -> DarkTreeResult<Vec<DarkLeaf<T>>>
Build the DarkTree
using .build() and
then produce a flattened vector containing
all the leafs in DFS post-order traversal order.
sourcefn check_min_capacity(&self) -> DarkTreeResult<()>
fn check_min_capacity(&self) -> DarkTreeResult<()>
Check if configured min capacity have not been exceeded.
sourcefn check_max_capacity(&self) -> DarkTreeResult<()>
fn check_max_capacity(&self) -> DarkTreeResult<()>
Check if configured max capacity have been exceeded.
sourcepub fn append(&mut self, child: DarkTree<T>) -> DarkTreeResult<()>
pub fn append(&mut self, child: DarkTree<T>) -> DarkTreeResult<()>
Append a new child node to the DarkTree
,
if max capacity has not been exceeded. This call
doesn’t update the indexes, so either .index()
or .build() must be called after it.
sourcefn set_parent_children_indexes(&mut self, parent_index: Option<usize>)
fn set_parent_children_indexes(&mut self, parent_index: Option<usize>)
Set DarkTree
’s leaf parent and children indexes,
and trigger the setup of its children indexes.
sourcefn index(&mut self)
fn index(&mut self)
Setup DarkTree
’s leafs indexes, based on DFS post-order
traversal order. This call assumes it was triggered for the
root of the tree, which has no parent index.
sourcefn check_parent_children_indexes(
&self,
parent_index: Option<usize>,
) -> DarkTreeResult<()>
fn check_parent_children_indexes( &self, parent_index: Option<usize>, ) -> DarkTreeResult<()>
Verify DarkTree
’s leaf parent and children indexes validity,
and trigger the check of its children indexes.
sourcefn integrity_check(&self) -> DarkTreeResult<()>
fn integrity_check(&self) -> DarkTreeResult<()>
Verify current DarkTree
’s leafs indexes validity,
based on DFS post-order traversal order. Additionally,
check that min and max capacities have been properly
configured, min capacity has been exceeded and max
capacity has not. This call assumes it was triggered
for the root of the tree, which has no parent index.
sourcefn iter(&self) -> DarkTreeIter<'_, T> ⓘ
fn iter(&self) -> DarkTreeIter<'_, T> ⓘ
Immutably iterate through the tree, using DFS post-order traversal.
sourcefn iter_mut(&mut self) -> DarkTreeIterMut<'_, T> ⓘ
fn iter_mut(&mut self) -> DarkTreeIterMut<'_, T> ⓘ
Mutably iterate through the tree, using DFS post-order traversal.
Trait Implementations§
source§impl<'a, T: Clone + Send + Sync> IntoIterator for &'a DarkTree<T>
impl<'a, T: Clone + Send + Sync> IntoIterator for &'a DarkTree<T>
Define fusion iteration behavior, allowing
us to use the DarkTreeIter
iterator in
loops directly, without using .iter() method
of DarkTree
.
source§impl<'a, T: Clone + Send + Sync> IntoIterator for &'a mut DarkTree<T>
impl<'a, T: Clone + Send + Sync> IntoIterator for &'a mut DarkTree<T>
Define fusion iteration behavior, allowing
us to use the DarkTreeIterMut
iterator
in loops directly, without using .iter_mut()
method of DarkTree
.
source§impl<T: Clone + Send + Sync> IntoIterator for DarkTree<T>
impl<T: Clone + Send + Sync> IntoIterator for DarkTree<T>
Define fusion iteration behavior, allowing
us to use the DarkTreeIntoIter
.into_iter()
method, to consume the DarkTree
and iterate
over it.
source§impl<T: PartialEq + Clone + Send + Sync> PartialEq for DarkTree<T>
impl<T: PartialEq + Clone + Send + Sync> PartialEq for DarkTree<T>
impl<T: Clone + Send + Sync> StructuralPartialEq for DarkTree<T>
Auto Trait Implementations§
impl<T> Freeze for DarkTree<T>where
T: Freeze,
impl<T> RefUnwindSafe for DarkTree<T>where
T: RefUnwindSafe,
impl<T> Send for DarkTree<T>
impl<T> Sync for DarkTree<T>
impl<T> Unpin for DarkTree<T>where
T: Unpin,
impl<T> UnwindSafe for DarkTree<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.