HashedArrayTree

Struct HashedArrayTree 

Source
pub struct HashedArrayTree<T> { /* private fields */ }
Expand description

Hashed Array Tree (HAT) described by Edward Sitarski.

Implementations§

Source§

impl<T> HashedArrayTree<T>

Source

pub fn new() -> Self

Returns a hashed array tree with zero capacity.

Source

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

Appends an element to the back of a collection.

§Panics

Panics if a new block is allocated that would exceed isize::MAX bytes.

§Time complexity

O(N) in the worst case (expand).

Source

pub fn push_within_capacity(&mut self, value: T) -> Result<(), T>

Appends an element if there is sufficient spare capacity, otherwise an error is returned with the element.

§Time complexity

O(N) in the worst case (expand).

Source

pub fn get(&self, index: usize) -> Option<&T>

Retrieve a reference to the element at the given offset.

§Time complexity

Constant time.

Source

pub fn get_mut(&mut self, index: usize) -> Option<&mut T>

Returns a mutable reference to an element.

§Time complexity

Constant time.

Source

pub fn pop(&mut self) -> Option<T>

Removes the last element from the array and returns it, or None if the array is empty.

§Time complexity

O(N) in the worst case (shrink).

Source

pub fn pop_if(&mut self, predicate: impl FnOnce(&mut T) -> bool) -> Option<T>

Removes and returns the last element from an array if the predicate returns true, or None`` if the predicate returns false`` or the array is empty (the predicate will not be called in that case).

§Time complexity

O(N) in the worst case (shrink).

Source

pub fn swap_remove(&mut self, index: usize) -> T

Removes an element from the array and returns it.

The removed element is replaced by the last element of the array.

This does not preserve ordering of the remaining elements.

§Time complexity

O(N) in the worst case (shrink).

Source

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

Source

pub fn len(&self) -> usize

Return the number of elements in the array.

§Time complexity

Constant time.

Source

pub fn capacity(&self) -> usize

Returns the total number of elements the array can hold without reallocating.

§Time complexity

Constant time.

Source

pub fn is_empty(&self) -> bool

Returns true if the array has a length of 0.

§Time complexity

Constant time.

Source

pub fn clear(&mut self)

Clears the array, removing all values and deallocating all leaves.

§Time complexity

O(N) if elements are droppable, otherwise O(√N)

Trait Implementations§

Source§

impl<T> Default for HashedArrayTree<T>

Source§

fn default() -> Self

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

impl<T> Display for HashedArrayTree<T>

Source§

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

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

impl<T> Drop for HashedArrayTree<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<A> FromIterator<A> for HashedArrayTree<A>

Source§

fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<T> Index<usize> for HashedArrayTree<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

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

impl<T> IndexMut<usize> for HashedArrayTree<T>

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

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

impl<T> IntoIterator for HashedArrayTree<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = ArrayIntoIter<<HashedArrayTree<T> as IntoIterator>::Item>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T> Freeze for HashedArrayTree<T>

§

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

§

impl<T> !Send for HashedArrayTree<T>

§

impl<T> !Sync for HashedArrayTree<T>

§

impl<T> Unpin for HashedArrayTree<T>

§

impl<T> UnwindSafe for HashedArrayTree<T>
where T: RefUnwindSafe,

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

Source§

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

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.