IntTable

Struct IntTable 

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

Source

pub const fn new() -> Self

Creates a new, zero-capacity hashtable that will grow with insertions.

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new IntTable with the given capacity.

Source

pub fn remove(&mut self, key: u64) -> Option<V>

Removes the given key from the table, returning its associated value.

Source

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.

Source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the underlying table to the number of elements it contains.

Source

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

Reserves at least additional spots in the backing allocation. This might allocate more. You know the drill.

Source

pub fn capacity(&self) -> usize

Returns the map’s capacity

Source

pub fn clear(&mut self)

Removes all elements from self

Source

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.

Source

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.

Source

pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>

Tries to reserve addional capacity, but doesn’t abort the programme on failure.

Source

pub fn get(&self, key: u64) -> Option<&V>

Returns the value at key

Source

pub fn get_mut(&mut self, key: u64) -> Option<&mut V>

Returns a mutable reference to the value at key

Source

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.

Source

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.

Source

pub fn retain<F>(&mut self, p: F)
where F: FnMut(&u64, &mut V) -> bool,

Removes all values for which p evaluates to false.

Source

pub fn keys(&self) -> impl Iterator<Item = &u64>

Returns an iterator over the keys

Source

pub fn values(&self) -> impl Iterator<Item = &V>

Returns an iterator over the values

Source

pub fn values_mut(&mut self) -> impl Iterator<Item = &mut V>

Returns an iterator over mutable references to the stored values

Source

pub fn contains_key(&self, key: u64) -> bool

Self-documenting.

Source

pub fn entry(&mut self, key: u64) -> Entry<'_, V>

Gets the given key’s corresponding entry in the map for in-place manipulation.

Source

pub fn len(&self) -> usize

Returns the number of elements in the map

Source

pub fn is_empty(&self) -> bool

Self-documenting.

Source

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

Source

pub fn drain(&mut self) -> impl Iterator<Item = (u64, V)> + '_

Removes all values from self and returns an iterator over all (key, value) pairs.

Source

pub fn iter(&self) -> impl Iterator<Item = (&u64, &V)>

Returns an iterator over all (key, value) pairs.

Source

pub fn extract_if<F>( &mut self, f: F, ) -> ExtractIf<'_, V, impl FnMut(&mut (u64, V)) -> bool>
where F: FnMut(&u64, &mut 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.

Source

pub fn into_keys(self) -> impl Iterator<Item = u64>

Consumes self and returns an iterator over its keys.

Source

pub fn into_values(self) -> impl Iterator<Item = V>

Consumes self and returns an iterator over its values.

Source§

impl<V> IntTable<V>

Source

pub fn inner(&self) -> &HashTable<(u64, V)>

Returns the inner hashtable for your viewing pleasure.

Source

pub fn into_inner(self) -> HashTable<(u64, V)>

Unwraps the inner hashtable.

Trait Implementations§

Source§

impl<V> Debug for IntTable<V>
where V: Debug,

Source§

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

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

impl<V> Default for IntTable<V>

Source§

fn default() -> Self

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

impl<'de, T: Deserialize<'de>> Deserialize<'de> for IntTable<T>

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<V> Extend<(u64, V)> for IntTable<V>

Source§

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

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<V> FromIterator<(u64, V)> for IntTable<V>

Source§

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.

Source§

impl<V> Index<u64> for IntTable<V>

Source§

type Output = V

The returned type after indexing.
Source§

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

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

impl<V> IntoIterator for IntTable<V>

Source§

type Item = (u64, V)

The type of the elements being iterated over.
Source§

type IntoIter = IntTableIter<<IntTable<V> 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<V> PartialEq for IntTable<V>
where V: PartialEq,

Source§

fn eq(&self, other: &IntTable<V>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Serialize> Serialize for IntTable<T>

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<V> Freeze for IntTable<V>

§

impl<V> RefUnwindSafe for IntTable<V>
where V: RefUnwindSafe,

§

impl<V> Send for IntTable<V>
where V: Send,

§

impl<V> Sync for IntTable<V>
where V: Sync,

§

impl<V> Unpin for IntTable<V>
where V: Unpin,

§

impl<V> UnwindSafe for IntTable<V>
where V: UnwindSafe,

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> 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, 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,