Enum im_ternary_tree::TernaryTreeList
source · pub enum TernaryTreeList<T> {
Empty,
Tree(TernaryTree<T>),
}
Expand description
wraps TerarnaryTreeList with support for empty
Variants§
Implementations§
source§impl<T> TernaryTreeList<T>
impl<T> TernaryTreeList<T>
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
sourcepub fn format_inline(&self) -> String
pub fn format_inline(&self) -> String
turn into a representation in triples, _
for holes
sourcepub fn format_debug(&self) -> String
pub fn format_debug(&self) -> String
items in debug display
sourcepub fn get(&self, idx: usize) -> Option<&T>
pub fn get(&self, idx: usize) -> Option<&T>
get element in list by reference
PERF: recursive function is slower than iterative loop with Cell in bench(using usize
),
however, Calcit is heavy in cloning(reference though… according real practice),
so here we still choose ref_get
for speed in Calcit project.
sourcepub fn find_index(&self, f: Arc<dyn Fn(&T) -> bool>) -> Option<i64>
pub fn find_index(&self, f: Arc<dyn Fn(&T) -> bool>) -> Option<i64>
find position of matched element in list(if exists)
sourcepub fn last_index_of(&self, item: &T) -> Option<usize>
pub fn last_index_of(&self, item: &T) -> Option<usize>
index of element from end, return 0 if found at last
sourcepub fn loop_get(&self, original_idx: usize) -> Option<&T>
pub fn loop_get(&self, original_idx: usize) -> Option<&T>
unchecked get via go down the branch with a mutable loop
this function is SLOWER compared to ref_get
, not used by default
pub fn first(&self) -> Option<&T>
pub fn last(&self) -> Option<&T>
pub fn assoc(&self, idx: usize, item: T) -> Result<Self, String>
pub fn dissoc(&self, idx: usize) -> Result<Self, String>
pub fn butlast(&self) -> Result<Self, String>
pub fn insert(&self, idx: usize, item: T, after: bool) -> Result<Self, String>
pub fn assoc_before(&self, idx: usize, item: T) -> Result<Self, String>
pub fn assoc_after(&self, idx: usize, item: T) -> Result<Self, String>
pub fn force_inplace_balancing(&mut self) -> Result<(), String>
pub fn unshift(&self, item: T) -> Self
pub fn prepend(&self, item: T) -> Self
pub fn push(&self, item: T) -> Self
sourcepub fn append(&self, item: T) -> Self
pub fn append(&self, item: T) -> Self
insert_after last element, this not optimzed for performance
sourcepub fn push_right(&self, item: T) -> Self
pub fn push_right(&self, item: T) -> Self
optimized for amortized O(1)
performance at best cases
sourcepub fn push_left(&self, item: T) -> Self
pub fn push_left(&self, item: T) -> Self
optimized for amortized O(1)
performance at best cases
pub fn drop_left(&self) -> Self
sourcepub fn drop_left_shallow(&self) -> Self
pub fn drop_left_shallow(&self) -> Self
optimized for amortized O(1)
at best cases, but copies a lot
pub fn drop_right(&self) -> Self
sourcepub fn split(self, idx: usize) -> (Self, Self)
pub fn split(self, idx: usize) -> (Self, Self)
split into 2 lists, either could be Empty notice if index is too large, (Self, Empty) is returned, not providing index out of bound error
sourcepub fn drop_right_shallow(&self) -> Self
pub fn drop_right_shallow(&self) -> Self
optimized for amortized O(1)
at best cases, but copies a lot
pub fn concat(raw: &[TernaryTreeList<T>]) -> Self
pub fn check_structure(&self) -> Result<(), String>
pub fn slice(&self, start_idx: usize, end_idx: usize) -> Result<Self, String>
pub fn skip(&self, idx: usize) -> Result<Self, String>
pub fn take(&self, idx: usize) -> Result<Self, String>
pub fn reverse(&self) -> Self
pub fn map<V>(&self, f: Arc<dyn Fn(&T) -> V>) -> TernaryTreeList<V>
pub fn to_vec(&self) -> Vec<T>
sourcepub fn traverse(&self, f: &mut dyn FnMut(&T))
pub fn traverse(&self, f: &mut dyn FnMut(&T))
traverse all elements in list, use referenced value
sourcepub fn traverse_result<S>(
&self,
f: &mut dyn FnMut(&T) -> Result<(), S>
) -> Result<(), S>
pub fn traverse_result<S>( &self, f: &mut dyn FnMut(&T) -> Result<(), S> ) -> Result<(), S>
traverse elements in list, use referenced value,
returns Ok
when all elements are traversed
pub fn iter(&self) -> TernaryTreeListRefIntoIterator<'_, T> ⓘ
Trait Implementations§
source§impl<T: Clone> Clone for TernaryTreeList<T>
impl<T: Clone> Clone for TernaryTreeList<T>
source§fn clone(&self) -> TernaryTreeList<T>
fn clone(&self) -> TernaryTreeList<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T: Debug> Debug for TernaryTreeList<T>
impl<T: Debug> Debug for TernaryTreeList<T>
source§impl<T> Display for TernaryTreeList<T>
impl<T> Display for TernaryTreeList<T>
source§impl<T> From<&Vec<T>> for TernaryTreeList<T>
impl<T> From<&Vec<T>> for TernaryTreeList<T>
source§impl<T> From<Vec<T>> for TernaryTreeList<T>
impl<T> From<Vec<T>> for TernaryTreeList<T>
source§impl<T> Hash for TernaryTreeList<T>
impl<T> Hash for TernaryTreeList<T>
source§impl<T> Index<usize> for TernaryTreeList<T>
impl<T> Index<usize> for TernaryTreeList<T>
source§impl<'a, T> IntoIterator for &'a TernaryTreeList<T>
impl<'a, T> IntoIterator for &'a TernaryTreeList<T>
source§impl<T> Ord for TernaryTreeList<T>
impl<T> Ord for TernaryTreeList<T>
source§impl<T: Clone + Display + Eq + PartialEq + Debug + Ord + PartialOrd + Hash> PartialEq for TernaryTreeList<T>
impl<T: Clone + Display + Eq + PartialEq + Debug + Ord + PartialOrd + Hash> PartialEq for TernaryTreeList<T>
source§impl<T> PartialOrd for TernaryTreeList<T>
impl<T> PartialOrd for TernaryTreeList<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more