Skip to main content

AvlTree

Struct AvlTree 

Source
pub struct AvlTree<P, T> { /* private fields */ }
Expand description

An AVL tree of payloads by position, its nodes kept in a list.

A node can stand at a position without a payload, as music21’s createNodeAtPosition leaves one.

Implementations§

Source§

impl<P: PartialOrd + Clone, T> AvlTree<P, T>

Source

pub fn new() -> Self

An empty tree.

Source

pub fn from_sorted(items: Vec<(P, T)>) -> Self

A balanced tree of items sorted by strictly rising position.

Source

pub fn insert(&mut self, position: P, payload: T)

Puts a payload at a position, replacing what was there.

Source

pub fn get(&self, position: &P) -> Option<&T>

The payload at a position.

Source

pub fn remove(&mut self, position: &P)

Takes out the node at a position.

Source

pub fn position_after(&self, position: &P) -> Option<&P>

The first position after one given.

Source

pub fn position_before(&self, position: &P) -> Option<&P>

The last position before one given.

Source

pub fn root_position(&self) -> Option<&P>

The root’s position.

Source

pub fn height(&self) -> Option<i64>

The root’s height; none for an empty tree.

Source

pub fn iter(&self) -> impl Iterator<Item = (&P, Option<&T>)>

Every position and payload, left to right.

Trait Implementations§

Source§

impl<P: PartialOrd + Clone, T> AvlNodes for AvlTree<P, T>

Source§

type Node = usize

A handle on one node.
Source§

type Position = P

Where a node stands.
Source§

type Error = TreeError

What reading or writing a node can fail with.
Source§

fn left(&self, node: &usize) -> Result<Option<usize>, TreeError>

The node’s left child.
Source§

fn right(&self, node: &usize) -> Result<Option<usize>, TreeError>

Its right child.
Source§

fn set_left( &mut self, node: &usize, child: Option<usize>, ) -> Result<(), TreeError>

Sets its left child.
Source§

fn set_right( &mut self, node: &usize, child: Option<usize>, ) -> Result<(), TreeError>

Sets its right child.
Source§

fn shape(&self, node: &usize) -> Result<Shape, TreeError>

Its height and balance as last updated.
Source§

fn set_shape(&mut self, node: &usize, shape: Shape) -> Result<(), TreeError>

Sets its height and balance.
Source§

fn position(&self, node: &usize) -> Result<P, TreeError>

Its position.
Source§

fn holds( &self, node: &usize, compare: Compare, position: &P, ) -> Result<bool, TreeError>

Whether node.position <compare> position.
Source§

fn create(&mut self, position: &P) -> Result<usize, TreeError>

A new node at a position, holding nothing.
Source§

fn move_attributes(&mut self, from: &usize, to: &usize) -> Result<(), TreeError>

Moves what one node holds – its position and payload, not its links or shape – onto another: music21’s moveAttributes.
Source§

impl<P: Clone, T: Clone> Clone for AvlTree<P, T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<P: Debug, T: Debug> Debug for AvlTree<P, T>

Source§

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

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

impl<P, T> Default for AvlTree<P, T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<P, T> Forget for AvlTree<P, T>

§

impl<P, T> Freeze for AvlTree<P, T>
where Vec<Slot<P, T>>: Freeze,

§

impl<P, T> Move for AvlTree<P, T>

§

impl<P, T> RefUnwindSafe for AvlTree<P, T>
where Vec<Slot<P, T>>: RefUnwindSafe,

§

impl<P, T> Send for AvlTree<P, T>
where Vec<Slot<P, T>>: Send,

§

impl<P, T> Sync for AvlTree<P, T>
where Vec<Slot<P, T>>: Sync,

§

impl<P, T> Unpin for AvlTree<P, T>
where Vec<Slot<P, T>>: Unpin,

§

impl<P, T> UnsafeUnpin for AvlTree<P, T>
where Vec<Slot<P, T>>: UnsafeUnpin,

§

impl<P, T> UnwindSafe for AvlTree<P, T>
where Vec<Slot<P, T>>: UnwindSafe,

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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.