Struct multi_stash::MultiStash

source ·
pub struct MultiStash<T> { /* private fields */ }
Expand description

A vector-like data structure that is able to reuse slots for new elements.

Specifically allows for (armortized) O(1) instructions for:

Implementations§

source§

impl<T> MultiStash<T>

source

pub fn new() -> Self

Construct a new, empty MultiStash.

The MultiStash will not allocate until items are put into it.

source

pub fn with_capacity(capacity: usize) -> Self

Constructs a new, empty MultiStash with at least the specified capacity.

The MultiStash will be able to hold at least capacity elements without reallocating. This method is allowed to allocate for more elements than capacity. If capacity is 0, the MultiStash will not allocate.

It is important to note that although the returned MultiStash has the minimum capacity specified, the MultiStash will have a zero length. For an explanation of the difference between length and capacity, see Capacity and reallocation.

If it is important to know the exact allocated capacity of a MultiStash, always use the capacity method after construction.

Panics

Panics if the new capacity exceeds isize::MAX bytes.

source

pub fn capacity(&self) -> usize

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

source

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more elements to be inserted in the given MultiStash. The collection may reserve more space to speculatively avoid frequent reallocations. After calling reserve, capacity will be greater than or equal to self.len() + additional. Does nothing if capacity is already sufficient.

Panics

Panics if the new capacity exceeds isize::MAX bytes.

source

pub fn reserve_exact(&mut self, additional: usize)

Reserves the minimum capacity for at least additional more elements to be inserted in the given MultiStash. Unlike reserve, this will not deliberately over-allocate to speculatively avoid frequent allocations. After calling reserve_exact, capacity will be greater than or equal to self.len() + additional. Does nothing if the capacity is already sufficient.

Note that the allocator may give the collection more space than it requests. Therefore, capacity can not be relied upon to be precisely minimal. Prefer reserve if future insertions are expected.

Panics

Panics if the new capacity exceeds isize::MAX bytes.

source

pub fn len_items(&self) -> usize

Returns the number of items in the MultiStash.

Note

A single element might store multiple items.

source

pub fn len(&self) -> usize

Returns the number of elements in the MultiStash.

Note

A single element might store multiple items.

source

pub fn is_empty(&self) -> bool

Returns true if the MultiStash contains no elements.

source

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

Returns a reference to an element at the key if any.

source

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

Returns a mutable reference to an element at the key if any.

source

pub fn put(&mut self, amount: NonZeroUsize, item: T) -> Key

Puts an amount of item into the MultiStash.

Panics

Panics if the new capacity exceeds isize::MAX bytes.

source

pub fn clear(&mut self)

Clears the MultiStash, removing all elements.

Note that this method has no effect on the allocated capacity of the vector.

source

pub fn take_all(&mut self, key: Key) -> Option<(usize, T)>

Removes and returns the element at key and its amount of remaining items.

Returns None if key refers to a vacant entry or is out of bounds.

source

pub fn bump(&mut self, key: Key, amount: usize) -> Option<usize>

Bumps the amount of items of the element at key if any.

Returns None if not element is found at the key.

Panics

Panics if amount of the element at key overflows.

source

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

Returns an iterator over the elements of the MultiStash.

The iterator yields all elements, their keys and remaining items from start to end.

source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns an iterator over the elements of the MultiStash.

The iterator yields mutable references to all elements, their keys and remaining items from start to end.

source§

impl<T: Clone> MultiStash<T>

source

pub fn take_one(&mut self, key: Key) -> Option<(usize, T)>

Returns a single item of the element at key and the amount of remaining items after this operation.

Remove the element if no items are left after this operation. Returns None if key refers to a vacant entry or is out of bounds.

Trait Implementations§

source§

impl<T: Clone> Clone for MultiStash<T>

source§

fn clone(&self) -> MultiStash<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 MultiStash<T>

source§

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

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

impl<T> Default for MultiStash<T>

source§

fn default() -> Self

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

impl<T> Extend<(NonZeroUsize, T)> for MultiStash<T>

source§

fn extend<I: IntoIterator<Item = (NonZeroUsize, T)>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<T> FromIterator<(NonZeroUsize, T)> for MultiStash<T>

source§

fn from_iter<I: IntoIterator<Item = (NonZeroUsize, T)>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<T: Hash> Hash for MultiStash<T>

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<Key> for MultiStash<T>

§

type Output = T

The returned type after indexing.
source§

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

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

impl<T> IndexMut<Key> for MultiStash<T>

source§

fn index_mut(&mut self, key: Key) -> &mut Self::Output

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

impl<'a, T> IntoIterator for &'a MultiStash<T>

§

type Item = (Key, usize, &'a T)

The type of the elements being iterated over.
§

type IntoIter = Iter<'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<'a, T> IntoIterator for &'a mut MultiStash<T>

§

type Item = (Key, usize, &'a mut T)

The type of the elements being iterated over.
§

type IntoIter = IterMut<'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> IntoIterator for MultiStash<T>

§

type Item = (Key, usize, T)

The type of the elements being iterated over.
§

type IntoIter = IntoIter<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> Ord for MultiStash<T>

source§

fn cmp(&self, other: &MultiStash<T>) -> Ordering

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

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

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

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

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

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

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

impl<T: PartialEq> PartialEq for MultiStash<T>

source§

fn eq(&self, other: &MultiStash<T>) -> 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> PartialOrd for MultiStash<T>

source§

fn partial_cmp(&self, other: &MultiStash<T>) -> 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> Eq for MultiStash<T>

source§

impl<T> StructuralEq for MultiStash<T>

source§

impl<T> StructuralPartialEq for MultiStash<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for MultiStash<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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, U> TryFrom<U> for Twhere 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 Twhere 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.