Struct smallmap::Map

source ·
pub struct Map<TKey, TValue>(/* private fields */);
Expand description

A small hashtable-like map with byte sized key indecies.

Implementations§

source§

impl<K, V> Map<K, V>where K: Collapse,

source

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

Get an Entry for the key that lets you get or insert the value

source

pub fn clean(&mut self)

Remove all empty pages from this instance.

source

pub fn len(&self) -> usize

The number of entries currently in this map

This is an iterating count over all slots in all current pages, if possible store it in a temporary instead of re-calling it.

source

pub fn is_empty(&self) -> bool

Is this map empty

source

pub fn num_pages(&self) -> usize

The number of pages currently in this map

source

pub fn into_pages(self) -> Vec<Page<K, V>>

Consume the instance, returning all pages.

source

pub fn pages(&self) -> Pages<'_, K, V>

An iterator over all pages

source

pub fn pages_mut(&mut self) -> PagesMut<'_, K, V>

A mutable iterator over all pages

source

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

An iterator over all elements in the map

source

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

An iterator over all the keys in the map

source

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

An iterator over all the values in the map

source

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

A mutable iterator over all the values in the map

source

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

A mutable iterator over all elements in the map

source

pub fn new() -> Self

Create a new empty Map

source

pub fn with_capacity(pages: usize) -> Self

Create a new empty Map with a specific number of pages pre-allocated

source

pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>where K: Borrow<Q>, Q: Collapse + Eq + ?Sized,

Get a mutable reference of the value corresponding to this key if it is in the map.

source

pub fn contains_key<Q>(&self, key: &Q) -> boolwhere K: Borrow<Q>, Q: Collapse + Eq + ?Sized,

Search the map for entry corresponding to this key

source

pub fn get<Q>(&self, key: &Q) -> Option<&V>where K: Borrow<Q>, Q: Collapse + Eq + ?Sized,

Get a reference of the value corresponding to this key if it is in the map.

source

pub fn remove<Q>(&mut self, key: &Q) -> Option<V>where K: Borrow<Q>, Q: Collapse + Eq + ?Sized,

Remove the entry corresponding to this key in the map, returning the value if it was present

source

pub fn insert(&mut self, key: K, value: V) -> Option<V>

Insert a new key-value entry into this map, returning the pervious value if it was present

source

pub fn reverse(self) -> Map<V, K>where V: Collapse,

Consume this Map by swapping its keys and values around.

Trait Implementations§

source§

impl<TKey: Clone, TValue: Clone> Clone for Map<TKey, TValue>

source§

fn clone(&self) -> Map<TKey, TValue>

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<TKey: Debug, TValue: Debug> Debug for Map<TKey, TValue>

source§

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

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

impl<K: Collapse, V> Default for Map<K, V>

source§

fn default() -> Self

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

impl<K: Collapse, V> Extend<(K, V)> for Map<K, V>

source§

fn extend<T: IntoIterator<Item = (K, 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<K: Collapse, V> FromIterator<(K, V)> for Map<K, V>

source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<TKey: Hash, TValue: Hash> Hash for Map<TKey, TValue>

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<K, Q, V> Index<&Q> for Map<K, V>where K: Collapse + Borrow<Q>, Q: ?Sized + Collapse + Eq,

§

type Output = V

The returned type after indexing.
source§

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

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

impl<K, Q, V> IndexMut<&Q> for Map<K, V>where K: Collapse + Borrow<Q>, Q: ?Sized + Collapse + Eq,

source§

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

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

impl<K: Collapse, V> IntoIterator for Map<K, V>

source§

fn into_iter(self) -> Self::IntoIter

Consume this map into an iterator over all currently inserted entries

§

type Item = (K, V)

The type of the elements being iterated over.
§

type IntoIter = IntoIter<K, V>

Which kind of iterator are we turning this into?
source§

impl<TKey: PartialEq, TValue: PartialEq> PartialEq for Map<TKey, TValue>

source§

fn eq(&self, other: &Map<TKey, TValue>) -> 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<TKey: Eq, TValue: Eq> Eq for Map<TKey, TValue>

source§

impl<TKey, TValue> StructuralEq for Map<TKey, TValue>

source§

impl<TKey, TValue> StructuralPartialEq for Map<TKey, TValue>

Auto Trait Implementations§

§

impl<TKey, TValue> RefUnwindSafe for Map<TKey, TValue>where TKey: RefUnwindSafe, TValue: RefUnwindSafe,

§

impl<TKey, TValue> Send for Map<TKey, TValue>where TKey: Send, TValue: Send,

§

impl<TKey, TValue> Sync for Map<TKey, TValue>where TKey: Sync, TValue: Sync,

§

impl<TKey, TValue> Unpin for Map<TKey, TValue>where TKey: Unpin, TValue: Unpin,

§

impl<TKey, TValue> UnwindSafe for Map<TKey, TValue>where TKey: UnwindSafe, TValue: 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> Collapse for Twhere T: Hash + Eq + ?Sized,

source§

fn collapse(&self) -> u8

Create the index key for this instance. This is similar in use to Hash::hash().
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.