Implementations
sourceimpl<K: Eq + Hash, V> HashVec<K, V>
impl<K: Eq + Hash, V> HashVec<K, V>
sourcepub fn with_capacity(capacity: usize) -> HashVec<K, V>
pub fn with_capacity(capacity: usize) -> HashVec<K, V>
Creates a new, empty hashvec with the specified capacity.
sourcepub fn from_vec(v: Vec<(K, V)>) -> HashVec<K, V>
pub fn from_vec(v: Vec<(K, V)>) -> HashVec<K, V>
Creates a hashvec from a vector of key-value pairs.
Internally, this uses HashVec::append_vec()
, which means that redundant keys’ entries will be overwritten and moved to the end of the hashvec sequentially.
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the hashvec can hold without reallocating.
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the hashvec, removing all entries.
Keep in mind this will not reallocate memory.
sourcepub fn insert(&mut self, k: K, v: V)
pub fn insert(&mut self, k: K, v: V)
Inserts an entry into the hashvec, or replaces an existing one.
sourcepub fn push(&mut self, entry: (K, V))
pub fn push(&mut self, entry: (K, V))
Appends an entry to the back of the hashvec.
If an entry with an identical key was already in the hashvec, it is removed before the new entry is inserted.
Panics
Panics if the new capacity either overflows usize
or exceeds isize::MAX
bytes.
sourcepub fn pop(&mut self) -> Option<(K, V)>
pub fn pop(&mut self) -> Option<(K, V)>
Removes the last entry from the hashvec and returns it (or None
if the hashvec is empty).
sourcepub fn append(&mut self, other: &mut HashVec<K, V>)
pub fn append(&mut self, other: &mut HashVec<K, V>)
Appends all entries of other
into Self
, leaving other
empty.
Panics
Panics if the number of elements in the hashvec either overflows usize
or exceeds isize::MAX
bytes
sourcepub fn append_vec(&mut self, v: Vec<(K, V)>)
pub fn append_vec(&mut self, v: Vec<(K, V)>)
Appends a vector of key-value pairs onto the hashvec.
Internally, this uses HashVec::push()
, which means that redundant keys’ entries will be overwritten and moved to the end of the hashvec sequentially.
sourcepub fn swap_keys(&mut self, key_a: &K, key_b: &K)
pub fn swap_keys(&mut self, key_a: &K, key_b: &K)
Swaps the location of the provided keys’ entries
If either one of the keys is not already in the hashvec, this is a no-op.
sourcepub fn swap_indices(&mut self, index_a: usize, index_b: usize)
pub fn swap_indices(&mut self, index_a: usize, index_b: usize)
Swaps the location of the entries at the provided indices
If either one of the indices exceeds the current length of the hashvec, this is a no-op.
sourcepub fn contains_key(&self, k: &K) -> bool
pub fn contains_key(&self, k: &K) -> bool
Returns true
if the hashvec contains an entry corresponding to the provided key.
sourcepub fn get(&self, k: &K) -> Option<&V>
pub fn get(&self, k: &K) -> Option<&V>
Returns a reference to the value corresponding to the key, if it exists.
sourcepub fn get_mut(&mut self, k: &K) -> Option<&mut V>
pub fn get_mut(&mut self, k: &K) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key, if it exists.
sourcepub fn rename(&mut self, old_key: &K, new_key: K) -> Option<&V>
pub fn rename(&mut self, old_key: &K, new_key: K) -> Option<&V>
Changes an entry’s key, preserving and returning a reference to the associated value.
If the hashvec did not have an entry corresponding to the old key, None
is returned.
sourcepub fn remove_key_entry(&mut self, k: &K) -> Option<(K, V)>
pub fn remove_key_entry(&mut self, k: &K) -> Option<(K, V)>
Removes a key from the hashvec, returning the stored key and value if the key was previously in the hashvec.
sourcepub fn index(&self, k: &K) -> Option<usize>
pub fn index(&self, k: &K) -> Option<usize>
Returns the index of the provided key, if the key exists.
sourcepub fn remove_key(&mut self, k: &K) -> Option<V>
pub fn remove_key(&mut self, k: &K) -> Option<V>
Removes a key from the hashvec, returning the stored value if the key was previously in the hashvec.
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 HashVec
. The collection may reserve more space to avoid frequent reallocations.
Panics
Panics if the new capacity either overflows usize
or exceeds isize::MAX
bytes.
sourcepub fn shrink_to(&mut self, min_capacity: usize)
pub fn shrink_to(&mut self, min_capacity: usize)
Shrinks the capacity of the hashvec with a lower limit.
The capacity will remain at least as large as both the length and the supplied value.
If the current capacity is less than the lower limit, this is a no-op.
sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the hashvec as much as possible, according to internal rules.
Trait Implementations
sourceimpl<'a, K: Eq + Hash, V> IntoIterator for &'a HashVec<K, V>
impl<'a, K: Eq + Hash, V> IntoIterator for &'a HashVec<K, V>
Auto Trait Implementations
impl<K, V> RefUnwindSafe for HashVec<K, V> where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for HashVec<K, V> where
K: Send,
V: Send,
impl<K, V> Sync for HashVec<K, V> where
K: Sync,
V: Sync,
impl<K, V> Unpin for HashVec<K, V> where
K: Unpin,
V: Unpin,
impl<K, V> UnwindSafe for HashVec<K, V> where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more