pub enum TernaryTreeList<T> {
    Empty,
    Tree(TernaryTree<T>),
}
Expand description

wraps TerarnaryTreeList with support for empty

Variants§

§

Empty

§

Tree(TernaryTree<T>)

Implementations§

source§

impl<T> TernaryTreeList<T>
where T: Clone + Display + Eq + PartialEq + Debug + Ord + PartialOrd + Hash,

source

pub fn is_empty(&self) -> bool

source

pub fn len(&self) -> usize

source

pub fn format_inline(&self) -> String

turn into a representation in triples, _ for holes

source

pub fn format_debug(&self) -> String

items in debug display

source

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.

source

pub fn find_index(&self, f: Arc<dyn Fn(&T) -> bool>) -> Option<i64>

find position of matched element in list(if exists)

source

pub fn index_of(&self, item: &T) -> Option<usize>

find position of element

source

pub fn last_index_of(&self, item: &T) -> Option<usize>

index of element from end, return 0 if found at last

source

pub fn eq_shape(&self, ys: &Self) -> bool

recursively check structure

source

pub fn ref_get(&self, idx: usize) -> Option<&T>

unchecked get reference of element

source

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

source

pub fn first(&self) -> Option<&T>

source

pub fn last(&self) -> Option<&T>

source

pub fn assoc(&self, idx: usize, item: T) -> Result<Self, String>

source

pub fn dissoc(&self, idx: usize) -> Result<Self, String>

source

pub fn rest(&self) -> Result<Self, String>

ternary tree operation of rest

source

pub fn butlast(&self) -> Result<Self, String>

source

pub fn insert(&self, idx: usize, item: T, after: bool) -> Result<Self, String>

source

pub fn assoc_before(&self, idx: usize, item: T) -> Result<Self, String>

source

pub fn assoc_after(&self, idx: usize, item: T) -> Result<Self, String>

source

pub fn force_inplace_balancing(&mut self) -> Result<(), String>

source

pub fn unshift(&self, item: T) -> Self

source

pub fn prepend(&self, item: T) -> Self

source

pub fn push(&self, item: T) -> Self

source

pub fn append(&self, item: T) -> Self

insert_after last element, this not optimzed for performance

source

pub fn push_right(&self, item: T) -> Self

optimized for amortized O(1) performance at best cases

source

pub fn push_left(&self, item: T) -> Self

optimized for amortized O(1) performance at best cases

source

pub fn drop_left(&self) -> Self

source

pub fn drop_left_shallow(&self) -> Self

optimized for amortized O(1) at best cases, but copies a lot

source

pub fn drop_right(&self) -> Self

source

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

source

pub fn drop_right_shallow(&self) -> Self

optimized for amortized O(1) at best cases, but copies a lot

source

pub fn concat(raw: &[TernaryTreeList<T>]) -> Self

source

pub fn check_structure(&self) -> Result<(), String>

source

pub fn slice(&self, start_idx: usize, end_idx: usize) -> Result<Self, String>

source

pub fn skip(&self, idx: usize) -> Result<Self, String>

source

pub fn take(&self, idx: usize) -> Result<Self, String>

source

pub fn reverse(&self) -> Self

source

pub fn map<V>(&self, f: Arc<dyn Fn(&T) -> V>) -> TernaryTreeList<V>

source

pub fn to_vec(&self) -> Vec<T>

source

pub fn traverse(&self, f: &mut dyn FnMut(&T))

traverse all elements in list, use referenced value

source

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

source

pub fn iter(&self) -> TernaryTreeListRefIntoIterator<'_, T>

Trait Implementations§

source§

impl<T: Clone> Clone for TernaryTreeList<T>

source§

fn clone(&self) -> TernaryTreeList<T>

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<T: Debug> Debug for TernaryTreeList<T>

source§

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

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

impl<T> Display for TernaryTreeList<T>
where T: Clone + Display + Eq + PartialEq + Debug + Ord + PartialOrd + Hash,

source§

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

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

impl<T, const N: usize> From<&[T; N]> for TernaryTreeList<T>
where T: Clone + Display + Eq + PartialEq + Debug + Ord + PartialOrd + Hash,

source§

fn from(xs: &[T; N]) -> Self

Converts to this type from the input type.
source§

impl<T> From<&Vec<T>> for TernaryTreeList<T>
where T: Clone + Display + Eq + PartialEq + Debug + Ord + PartialOrd + Hash,

source§

fn from(xs: &Vec<T>) -> Self

Converts to this type from the input type.
source§

impl<T> From<Vec<T>> for TernaryTreeList<T>
where T: Clone + Display + Eq + PartialEq + Debug + Ord + PartialOrd + Hash,

source§

fn from(xs: Vec<T>) -> Self

Converts to this type from the input type.
source§

impl<T> Hash for TernaryTreeList<T>
where T: Clone + Display + Eq + PartialEq + Debug + Ord + PartialOrd + 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<T> Index<usize> for TernaryTreeList<T>
where T: Clone + Display + Eq + PartialEq + Debug + Ord + PartialOrd + Hash,

§

type Output = T

The returned type after indexing.
source§

fn index<'b>(&self, idx: usize) -> &Self::Output

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

impl<'a, T> IntoIterator for &'a TernaryTreeList<T>
where T: Clone + Display + Eq + PartialEq + Debug + Ord + PartialOrd + Hash,

§

type Item = &'a T

The type of the elements being iterated over.
§

type IntoIter = TernaryTreeListRefIntoIterator<'a, T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T> Ord for TernaryTreeList<T>
where T: Clone + Display + Eq + PartialEq + Debug + Ord + PartialOrd + Hash,

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<T: Clone + Display + Eq + PartialEq + Debug + Ord + PartialOrd + Hash> PartialEq for TernaryTreeList<T>

source§

fn eq(&self, ys: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> PartialOrd for TernaryTreeList<T>
where T: Clone + Display + Eq + PartialEq + Debug + Ord + PartialOrd + Hash,

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T> Eq for TernaryTreeList<T>
where T: Clone + Display + Eq + PartialEq + Debug + Ord + PartialOrd + Hash,

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for TernaryTreeList<T>
where T: RefUnwindSafe,

§

impl<T> Send for TernaryTreeList<T>
where T: Sync + Send,

§

impl<T> Sync for TernaryTreeList<T>
where T: Sync + Send,

§

impl<T> Unpin for TernaryTreeList<T>
where T: Unpin,

§

impl<T> UnwindSafe for TernaryTreeList<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> ToOwned for T
where T: Clone,

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.