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>
impl<T> MultiStash<T>
sourcepub fn new() -> Self
pub fn new() -> Self
Construct a new, empty MultiStash
.
The MultiStash
will not allocate until items are put into it.
sourcepub fn with_capacity(capacity: usize) -> Self
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.
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the total number of elements the MultiStash
can hold without reallocating.
sourcepub fn reserve(&mut self, additional: usize)
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.
sourcepub fn reserve_exact(&mut self, additional: usize)
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.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the MultiStash
contains no elements.
sourcepub fn get(&self, key: Key) -> Option<(usize, &T)>
pub fn get(&self, key: Key) -> Option<(usize, &T)>
Returns a reference to an element at the key
if any.
sourcepub fn get_mut(&mut self, key: Key) -> Option<(usize, &mut T)>
pub fn get_mut(&mut self, key: Key) -> Option<(usize, &mut T)>
Returns a mutable reference to an element at the key
if any.
sourcepub fn put(&mut self, amount: NonZeroUsize, item: T) -> Key
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.
sourcepub fn clear(&mut self)
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.
sourcepub fn take_all(&mut self, key: Key) -> Option<(usize, T)>
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.
sourcepub fn bump(&mut self, key: Key, amount: usize) -> Option<usize>
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.
sourcepub fn iter(&self) -> Iter<'_, T> ⓘ
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.
sourcepub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
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>
impl<T: Clone> MultiStash<T>
Trait Implementations§
source§impl<T: Clone> Clone for MultiStash<T>
impl<T: Clone> Clone for MultiStash<T>
source§fn clone(&self) -> MultiStash<T>
fn clone(&self) -> MultiStash<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T: Debug> Debug for MultiStash<T>
impl<T: Debug> Debug for MultiStash<T>
source§impl<T> Default for MultiStash<T>
impl<T> Default for MultiStash<T>
source§impl<T> Extend<(NonZeroUsize, T)> for MultiStash<T>
impl<T> Extend<(NonZeroUsize, T)> for MultiStash<T>
source§fn extend<I: IntoIterator<Item = (NonZeroUsize, T)>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = (NonZeroUsize, T)>>(&mut self, iter: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<T> FromIterator<(NonZeroUsize, T)> for MultiStash<T>
impl<T> FromIterator<(NonZeroUsize, T)> for MultiStash<T>
source§fn from_iter<I: IntoIterator<Item = (NonZeroUsize, T)>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = (NonZeroUsize, T)>>(iter: I) -> Self
source§impl<T: Hash> Hash for MultiStash<T>
impl<T: Hash> Hash for MultiStash<T>
source§impl<T> Index<Key> for MultiStash<T>
impl<T> Index<Key> for MultiStash<T>
source§impl<T> IndexMut<Key> for MultiStash<T>
impl<T> IndexMut<Key> for MultiStash<T>
source§impl<'a, T> IntoIterator for &'a MultiStash<T>
impl<'a, T> IntoIterator for &'a MultiStash<T>
source§impl<'a, T> IntoIterator for &'a mut MultiStash<T>
impl<'a, T> IntoIterator for &'a mut MultiStash<T>
source§impl<T> IntoIterator for MultiStash<T>
impl<T> IntoIterator for MultiStash<T>
source§impl<T: Ord> Ord for MultiStash<T>
impl<T: Ord> Ord for MultiStash<T>
source§fn cmp(&self, other: &MultiStash<T>) -> Ordering
fn cmp(&self, other: &MultiStash<T>) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl<T: PartialEq> PartialEq for MultiStash<T>
impl<T: PartialEq> PartialEq for MultiStash<T>
source§fn eq(&self, other: &MultiStash<T>) -> bool
fn eq(&self, other: &MultiStash<T>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<T: PartialOrd> PartialOrd for MultiStash<T>
impl<T: PartialOrd> PartialOrd for MultiStash<T>
source§fn partial_cmp(&self, other: &MultiStash<T>) -> Option<Ordering>
fn partial_cmp(&self, other: &MultiStash<T>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more