Skip to main content

AvlTree

Struct AvlTree 

Source
pub struct AvlTree<T: Ord> { /* private fields */ }
Expand description

An AVL self-balancing binary search tree.

All operations (insert, contains) run in O(log n) worst-case time. The height is always ≤ 1.44 * log2(n + 2).

Implementations§

Source§

impl<T: Ord> AvlTree<T>

Source

pub fn new() -> Self

Create a new empty AVL tree.

Source

pub fn insert(&mut self, value: T)

Insert a value into the tree.

Duplicate values are ignored. Time complexity: O(log n).

Source

pub fn contains(&self, value: &T) -> bool

Return true if value is in the tree.

Time complexity: O(log n).

Source

pub fn height(&self) -> usize

Return the height of the tree (0 for an empty tree).

Source

pub fn len(&self) -> usize

Return the number of elements in the tree.

Source

pub fn is_empty(&self) -> bool

Return true if the tree contains no elements.

Trait Implementations§

Source§

impl<T: Ord> Default for AvlTree<T>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<T> Freeze for AvlTree<T>

§

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

§

impl<T> Send for AvlTree<T>
where T: Send,

§

impl<T> Sync for AvlTree<T>
where T: Sync,

§

impl<T> Unpin for AvlTree<T>

§

impl<T> UnsafeUnpin for AvlTree<T>

§

impl<T> UnwindSafe for AvlTree<T>
where 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> 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, 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.