pub struct IntTable<V> { /* private fields */ }Expand description
A Map associating unique integers and randomly distributed integers to values.
Tries to match std::collections::HashMap’s API, but leaves out functions that either don’t
apply (anything to do with hashers), or that just don’t make sense (like
std::collections::HashMap::get_key_value, as the key can just be copied).
This is also the reason why this doesn’t include any code examples. In fact, I could leave this entire crate undocumented and just tell you to look at the built-in hashmap.
Implementations§
Source§impl<V> IntTable<V>
impl<V> IntTable<V>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new, zero-capacity hashtable that will grow with insertions.
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new IntTable with the given capacity.
Sourcepub fn remove(&mut self, key: u64) -> Option<V>
pub fn remove(&mut self, key: u64) -> Option<V>
Removes the given key from the table, returning its associated value.
Sourcepub fn shrink_to(&mut self, min_capacity: usize)
pub fn shrink_to(&mut self, min_capacity: usize)
Shrinks the capacity of the table with a lower limit. It will drop down no lower than the supplied limit.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the underlying table to the number of elements it contains.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves at least additional spots in the backing allocation. This might allocate more.
You know the drill.
Sourcepub fn insert(&mut self, key: u64, value: V) -> Option<V>
pub fn insert(&mut self, key: u64, value: V) -> Option<V>
Insertns the given key-value pair into the table, returning the old value at key if there
was one.
Sourcepub fn try_insert(&mut self, key: u64, value: V) -> Result<&mut V, V>
pub fn try_insert(&mut self, key: u64, value: V) -> Result<&mut V, V>
Attempts to insert value at key, but if key was occupied, this function doesn’t
replace the old value.
Sourcepub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve addional capacity, but doesn’t abort the programme on failure.
Sourcepub fn get_mut(&mut self, key: u64) -> Option<&mut V>
pub fn get_mut(&mut self, key: u64) -> Option<&mut V>
Returns a mutable reference to the value at key
Sourcepub fn get_many_mut<const N: usize>(
&mut self,
ks: [u64; N],
) -> Option<[&mut V; N]>
pub fn get_many_mut<const N: usize>( &mut self, ks: [u64; N], ) -> Option<[&mut V; N]>
Attempts to get mutable references to N values in the map at once.
Returns an array of length N with the results of each query. For soundness, at most one
mutable reference will be returned to any value. None will be returned if any of the keys
are duplicates or missing.
Sourcepub unsafe fn get_many_unchecked_mut<const N: usize>(
&mut self,
ks: [u64; N],
) -> Option<[&mut V; N]>
pub unsafe fn get_many_unchecked_mut<const N: usize>( &mut self, ks: [u64; N], ) -> Option<[&mut V; N]>
Attempts to get mutable references to N values in the map at once, without validating
that the values are unique.
Returns an array of length N with the resultsn of each query.
None will be returned if one of the keys are missing.
For a safe alternative see [get_many_mut]
§Safety
Calling this method with overlapping keys is undefined behaviour even if the resulting references are not used.
Sourcepub fn values_mut(&mut self) -> impl Iterator<Item = &mut V>
pub fn values_mut(&mut self) -> impl Iterator<Item = &mut V>
Returns an iterator over mutable references to the stored values
Sourcepub fn contains_key(&self, key: u64) -> bool
pub fn contains_key(&self, key: u64) -> bool
Self-documenting.
Sourcepub fn entry(&mut self, key: u64) -> Entry<'_, V>
pub fn entry(&mut self, key: u64) -> Entry<'_, V>
Gets the given key’s corresponding entry in the map for in-place manipulation.
Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = (&u64, &mut V)>
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&u64, &mut V)>
Returns an iterator over the mutable values, but provides a key. For API consistency, it returns a reference to the key as well (instead of passing it by value).
Sourcepub fn drain(&mut self) -> impl Iterator<Item = (u64, V)> + '_
pub fn drain(&mut self) -> impl Iterator<Item = (u64, V)> + '_
Removes all values from self and returns an iterator over all (key, value) pairs.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&u64, &V)>
pub fn iter(&self) -> impl Iterator<Item = (&u64, &V)>
Returns an iterator over all (key, value) pairs.
Sourcepub fn extract_if<F>(
&mut self,
f: F,
) -> ExtractIf<'_, V, impl FnMut(&mut (u64, V)) -> bool> ⓘ
pub fn extract_if<F>( &mut self, f: F, ) -> ExtractIf<'_, V, impl FnMut(&mut (u64, V)) -> bool> ⓘ
Like Self::retain, but allows you to reuse the values removed in this fashion. Also,
this one removes the value if the predicate evaluates to true.
Note that this lets the filter closure mutate every value, regardless of whether or not it shall be kept in the map.
If the returned iterator is not exhausted, like if it was dropped without iterating or the iteration short-circuits, then the remaining elements will be retained.
Sourcepub fn into_keys(self) -> impl Iterator<Item = u64>
pub fn into_keys(self) -> impl Iterator<Item = u64>
Consumes self and returns an iterator over its keys.
Sourcepub fn into_values(self) -> impl Iterator<Item = V>
pub fn into_values(self) -> impl Iterator<Item = V>
Consumes self and returns an iterator over its values.
Trait Implementations§
Source§impl<'de, T: Deserialize<'de>> Deserialize<'de> for IntTable<T>
impl<'de, T: Deserialize<'de>> Deserialize<'de> for IntTable<T>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<V> Extend<(u64, V)> for IntTable<V>
impl<V> Extend<(u64, V)> for IntTable<V>
Source§fn extend<T: IntoIterator<Item = (u64, V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (u64, V)>>(&mut self, iter: T)
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<V> FromIterator<(u64, V)> for IntTable<V>
impl<V> FromIterator<(u64, V)> for IntTable<V>
Source§fn from_iter<T: IntoIterator<Item = (u64, V)>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = (u64, V)>>(iter: T) -> Self
Constructs an IntTable from an iterator. Note that this deduplicates the values and keeps the last value.