[][src]Struct total_order_multi_map::TotalOrderMultiMap

pub struct TotalOrderMultiMap<K, V> where
    V: StableDeref + DerefMut,
    K: Hash + Eq + Copy
{ /* fields omitted */ }

A multi map with keeps the total ordering of inserted elements

The map is meant to contain values implementing StableDeref, methods like get and iter will iterate over the inner values referred to when dereferencing the values.

The key is currently limited to values implementing Copy.

See the module/crate level documentation for more details.

Unwind Safety

This type is unwind + resume safe. Through in the unlikely case that a panic happens inside of a function like insert,get the resulting state might be inconsistent in a safe way, i.e. some values might be in the map, accessible during iteration but hey won't appear when using get.

Note that this can only happen in a few rare cases:

  1. Vec::pop/Vec::reserve panics
  2. HashMap::insert/HashMap::reserve panics
  3. for some reason oom does panic instead of aborting

Which mainly can happen in mainly following cases:

  • the vector of key-value pairs tries to contain more then isize::MAX bytes
  • you use zero-sized values and overflow usize (which can't really happen as we store at last some data per inserting, i.e. you would overflow the vec first)

Generally speaking you won't run into any of this in normal circumstances and if you do it's likely that you are close to a system wide oom anyway.

Methods

impl<K, V> TotalOrderMultiMap<K, V> where
    K: Hash + Eq + Copy,
    V: StableDeref + DerefMut
[src]

Important traits for Iter<'a, K, V>
pub fn iter(&self) -> Iter<K, V>[src]

Returns a iterator over the key value pairs in insertion order.

As this is a multi map a key can appear more than one time.

impl<K, V> TotalOrderMultiMap<K, V> where
    K: Hash + Eq + Copy,
    V: StableDeref + DerefMut
[src]

Important traits for IterMut<'a, K, V>
pub fn iter_mut(&mut self) -> IterMut<K, V>[src]

impl<K, V> TotalOrderMultiMap<K, V> where
    K: Hash + Eq + Copy,
    V: StableDeref + DerefMut
[src]

pub fn entry(&mut self, key: K) -> Entry<K, V>[src]

return a entry for a given key

impl<K, V> TotalOrderMultiMap<K, V> where
    K: Hash + Eq + Copy,
    V: StableDeref + DerefMut
[src]

Important traits for Keys<'a, K, T>
pub fn keys(&self) -> Keys<K, V::Target>[src]

Return an iterator the keys of this multi map.

each key will only be returned once, there is no specific order in which they keys are returned

Important traits for GroupedValues<'a, K, T>
pub fn group_iter(&self) -> GroupedValues<K, V::Target>[src]

Returns a iterator over all values grouped by key.

Important traits for GroupedValuesMut<'a, K, T>
pub fn group_iter_mut(&mut self) -> GroupedValuesMut<K, V::Target>[src]

Returns a iterator over all values grouped by key

Important traits for Values<'a, K, V>
pub fn values(&self) -> Values<K, V>[src]

Returns a iterator over the inner-values in this multi map.

Inner-Values are returned in the order they where inserted into the map. Note that

Important traits for ValuesMut<'a, K, V>
pub fn values_mut(&mut self) -> ValuesMut<K, V>[src]

Returns a iterator over the values in this multi map.

impl<K, V> TotalOrderMultiMap<K, V> where
    K: Hash + Eq + Copy,
    V: StableDeref + DerefMut
[src]

pub fn new() -> Self[src]

Create a new empty map.

pub fn with_capacity(capacity: usize) -> Self[src]

Crate a new map with a given capacity.

Note that this method will reserve the given capacity for the internal Vec and HashMap, but as it's a multi map it can not know how elements will be distributed, as such using with_capacity does not guarantee that there are no allocations if less than capacity elements are inserted. Through it still can reduce the number of allocations needed.

pub fn capacity(&self) -> usize[src]

Returns the capacity (unreliable).

This is not reliable as it only returns the capacity of the underlying Vec not considering the underlying HashMap or the Vec used to turn the map into a multi map.

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

Reserves space for n additional elements.

The reservation is done in both the internal Vec and HashMap but as the map is a multi map this method is less helpful as e.g. on a pure Vec or HashMap

Panics

if the new allocation size overflows usize

pub fn reverse(&mut self)[src]

Reverses insertion order.

After calling this the map will contains values as if they had been inserted in reversed order.

This will affect both the iteration order of the fill map as well as the iteration order of values returned by get.

pub fn shrink_to_fit(&mut self)[src]

Shrinks all internal containers to not contains any additional capacity.

Whether or not memory is freed depends in the dens on the shrink_to_fit implementation of Vec and HashMap

pub fn len(&self) -> usize[src]

Returns the total number of elements.

pub fn key_count(&self) -> usize[src]

Returns the total number of different keys.

pub fn is_empty(&self) -> bool[src]

Returns true if the map is empty.

pub fn clear(&mut self)[src]

Empties this map.

pub fn contains_key(&self, k: K) -> bool[src]

Returns true if the key is contained in the map.

Does not state how many values are associated with it.

Important traits for EntryValues<'a, T>
pub fn get(&self, k: K) -> EntryValues<V::Target>[src]

Returns values associated with the given key.

If the key is not in the map this will return None. This also means that EntryValues has at last one element.

Important traits for EntryValuesMut<'a, T>
pub fn get_mut(&mut self, k: K) -> EntryValuesMut<V::Target>[src]

Returns mutable references associated with the given key.

If the key is not in the map this will return None. This means the EntryValuesMut has at last one element.

Important traits for EntryValuesMut<'a, T>
pub fn add(&mut self, key: K, value: V) -> EntryValuesMut<V::Target>[src]

Adds a value for a given key to the multi map.

Returns access the all values already added to the key previously and this now added value through EntryValuesMut

pub fn set(&mut self, key: K, value: V) -> Vec<V>[src]

Sets the value associated with the given key.

Values previously associated with the key are removed and returned.

pub fn pop(&mut self) -> Option<(K, V)>[src]

Remove and return the element last inserted.

pub fn truncate(&mut self, to_len: usize)[src]

Keeps the first to_len inserted headers, removing the remaining ones.

If to_len is equal or larger the current length nothing will happen.

This won't affect the capacity.

Which headers are keeps/removed depends on the insertion order of the headers in the map and is independent of the headers name or if there had been other headers with the same name inserted before/after.

pub fn remove_all(&mut self, key_to_remove: K) -> bool[src]

removes all values associated with the given key

I.e. this removes all key-value pairs which key is equal to the given key.

Returns true if at last one value was removed

pub fn retain<FN>(&mut self, func: FN) where
    FN: FnMut(K, &V::Target) -> bool
[src]

retains only key value pairs for which func returns true

All key-value pairs for with the predicate func returns false will be removed.

Trait Implementations

impl<K, V> Send for TotalOrderMultiMap<K, V> where
    SyncSendHelper<K, V>: Send,
    V: StableDeref + DerefMut,
    K: Hash + Eq + Copy
[src]

see SendSyncHelper

impl<K, V> Sync for TotalOrderMultiMap<K, V> where
    SyncSendHelper<K, V>: Sync,
    V: StableDeref + DerefMut,
    K: Hash + Eq + Copy
[src]

see SendSyncHelper

impl<K, V> Extend<(K, V)> for TotalOrderMultiMap<K, V> where
    K: Hash + Eq + Copy,
    V: StableDeref + DerefMut
[src]

impl<K, V> IntoIterator for TotalOrderMultiMap<K, V> where
    K: Hash + Eq + Copy,
    V: StableDeref + DerefMut
[src]

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?

impl<K, V> Clone for TotalOrderMultiMap<K, V> where
    K: Hash + Eq + Copy,
    V: StableDeref + DerefMut + Clone
[src]

impl<K, V> Default for TotalOrderMultiMap<K, V> where
    K: Hash + Eq + Copy,
    V: StableDeref + DerefMut
[src]

impl<K, V> Eq for TotalOrderMultiMap<K, V> where
    K: Hash + Eq + Copy,
    V: StableDeref + DerefMut + Eq
[src]

Compares for equality which does consider the insertion order

impl<K, V> PartialEq<TotalOrderMultiMap<K, V>> for TotalOrderMultiMap<K, V> where
    K: Hash + Eq + Copy,
    V: StableDeref + DerefMut + PartialEq<V>, 
[src]

Compares for equality which does consider the insertion order

impl<K, V> Debug for TotalOrderMultiMap<K, V> where
    K: Hash + Eq + Copy + Debug,
    V: StableDeref + DerefMut + Debug
[src]

impl<K, V> FromIterator<(K, V)> for TotalOrderMultiMap<K, V> where
    K: Hash + Eq + Copy,
    V: StableDeref + DerefMut
[src]

Auto Trait Implementations

impl<K, V> Unpin for TotalOrderMultiMap<K, V> where
    K: Unpin,
    V: Unpin

impl<K, V> UnwindSafe for TotalOrderMultiMap<K, V> where
    K: UnwindSafe,
    V: UnwindSafe,
    <V as Deref>::Target: RefUnwindSafe

impl<K, V> RefUnwindSafe for TotalOrderMultiMap<K, V> where
    K: RefUnwindSafe,
    V: RefUnwindSafe,
    <V as Deref>::Target: RefUnwindSafe

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]