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 raw_pop(&mut self) -> T

Like Self::pop() but without the Option wrapper.

Will panic if the array is empty.

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.

§Panics

Panics if the index is out of bounds.

§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)

Source

pub fn swap(&mut self, a: usize, b: usize)

Swap two elements in the array.

§Panics

Panics if either index is out of bounds.

Source

pub fn sort_unstable_by<F>(&mut self, compare: F)
where F: FnMut(&T, &T) -> Ordering,

Sorts the slice in ascending order with a comparison function, without preserving the initial order of equal elements.

This sort is unstable (i.e., may reorder equal elements), in-place (i.e., does not allocate), and O(n * log(n)) worst-case.

Implements the standard heapsort algorithm.

Source

pub fn dedup_by<F>(&mut self, same_bucket: F)
where F: FnMut(&T, &T) -> bool,

Removes all but the first of consecutive elements in the array satisfying a given equality relation.

The same_bucket function is passed references to two elements from the array and must determine if the elements compare equal. The elements are passed in reverse order from their order in the array, so if same_bucket(a, b) returns true, a is removed.

If the array is sorted, this removes all duplicates.

Source

pub fn append(&mut self, other: &mut Self)

Moves all the elements of other into self, leaving other empty.

Source

pub fn split_off(&mut self, at: usize) -> Self

Splits the collection into two at the given index.

Returns a newly allocated array containing the elements in the range [at, len). After the call, the original array will be left containing the elements [0, at).

§Panics

Panics if at > len.

§Time complexity

O(N)

Source

pub fn truncate(&mut self, len: usize)

Shortens the array, keeping the first len elements and dropping the rest.

If len is greater or equal to the array’s current length, this has no effect.

§Time complexity

O(N)

Trait Implementations§

Source§

impl<T: Clone> Clone for HashedArrayTree<T>

Source§

fn clone(&self) -> Self

Returns a duplicate 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> 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
Source§

impl<T: Send> Send for HashedArrayTree<T>

Auto Trait Implementations§

§

impl<T> Freeze for HashedArrayTree<T>

§

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

§

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