pub struct Bijection<K, V> { /* private fields */ }
Expand description

Implements a bijection (one-to-one function) between a set of keys and a set of values. Mapping from key to value and from value to key are both O(1) operations.

Implementations§

source§

impl<K, V> Bijection<K, V>

source

pub fn new(default_key: K, default_value: V) -> Self

Creates a new Bijection with the given default key and value.

source

pub fn k2v(&self) -> &HashMapWithDefault<K, V>

Returns a reference to the hash table which maps keys to values.

source

pub fn v2k(&self) -> &HashMapWithDefault<V, K>

Returns a reference to the hash table which maps values to keys.

source§

impl<K: Clone + Hash + Eq, V: Clone + Hash + Eq> Bijection<K, V>

source

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

Inserts the given (key, value) pair. If this replaces an existing pair, then the old pair is returned.

source§

impl<K: Hash + Eq, V> Bijection<K, V>

source

pub fn value<Q: ?Sized + Hash + Eq>(&self, key: &Q) -> &Vwhere K: Borrow<Q>,

Returns the value associated with the given key. If no value is associated, then the default value is returned.

source§

impl<K, V: Hash + Eq> Bijection<K, V>

source

pub fn key<R: ?Sized + Hash + Eq>(&self, value: &R) -> &Kwhere V: Borrow<R>,

Returns the key associated with the given value. If no key is associated, then the default key is returned.

Auto Trait Implementations§

§

impl<K, V> RefUnwindSafe for Bijection<K, V>where K: RefUnwindSafe, V: RefUnwindSafe,

§

impl<K, V> Send for Bijection<K, V>where K: Send, V: Send,

§

impl<K, V> Sync for Bijection<K, V>where K: Sync, V: Sync,

§

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

§

impl<K, V> UnwindSafe for Bijection<K, V>where K: UnwindSafe, V: 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
§

impl<T> Free for T

§

unsafe default fn free(ptr_ref: NonNull<T>)

Drops the content pointed by this pointer and frees it. 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 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, 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.