Skip to main content

Bimap

Struct Bimap 

Source
pub struct Bimap<K, V, S = RandomState> { /* private fields */ }

Implementations§

Source§

impl<K, V> Bimap<K, V, RandomState>
where K: Eq + Hash + Clone, V: Eq + Hash + Clone,

Source

pub fn new() -> Self

Creates an empty Bimap.

Source§

impl<K, V, S> Bimap<K, V, S>
where K: Eq + Hash + Clone, V: Eq + Hash + Clone, S: BuildHasher + Clone + Default,

Source

pub fn with_hasher(hash_builder: S) -> Self

Creates a Bimap with the given hasher.

Source

pub fn from_hash_map(fwd: HashMap<K, V, S>) -> Self

Creates a bimap from a HashMap.

Source

pub fn len(&self) -> usize

Returns the number of elements in the bimap.

Source

pub fn is_empty(&self) -> bool

Returns whether the bimap is empty.

Source

pub fn clear(&mut self)

Removes all elements from the bimap.

Source

pub fn insert(&mut self, k: K, v: V)

Inserts a (key, value) pair into the bimap. Panics if either the key or value is already present in the bimap; to change a key or value, call either remove_fwd or remove_rev before inserting the new (key, value) pair.

Source

pub fn fwd(&self) -> &HashMap<K, V, S>

Gets the forward HashMap.

Source

pub fn rev(&self) -> &HashMap<V, K, S>

Gets the reverse HashMap.

Source

pub fn get_fwd<KeyBorrow>(&self, k: &KeyBorrow) -> Option<&V>
where K: Borrow<KeyBorrow>, KeyBorrow: Hash + Eq + ?Sized,

Gets the value corresponding to a key.

Source

pub fn get_rev<ValBorrow>(&self, v: &ValBorrow) -> Option<&K>
where V: Borrow<ValBorrow>, ValBorrow: Hash + Eq + ?Sized,

Gets the key corresponding to a value.

Source

pub fn remove_fwd<KeyBorrow>(&mut self, k: &KeyBorrow) -> V
where K: Borrow<KeyBorrow>, KeyBorrow: Hash + Eq + ?Sized,

Removes the (key, value) pair with the given key; returns the corresponding value.

Source

pub fn remove_rev<ValBorrow>(&mut self, v: &ValBorrow) -> K
where V: Borrow<ValBorrow>, ValBorrow: Hash + Eq + ?Sized,

Removes the (key, value) pair with the given value; returns the corresponding key.

Source

pub fn contains_fwd<KeyBorrow>(&self, k: &KeyBorrow) -> bool
where K: Borrow<KeyBorrow>, KeyBorrow: Hash + Eq + ?Sized,

Returns whether the bimap contains a (key, value) pair with the given key.

Source

pub fn contains_rev<ValBorrow>(&self, v: &ValBorrow) -> bool
where V: Borrow<ValBorrow>, ValBorrow: Hash + Eq + ?Sized,

Returns whether the bimap contains a (key, value) pair with the given value.

Source

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

Iterates over all (key, value) pairs in the bimap.

Trait Implementations§

Source§

impl<K: Clone, V: Clone, S: Clone> Clone for Bimap<K, V, S>

Source§

fn clone(&self) -> Bimap<K, V, S>

Returns a duplicate 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<K: Debug, V: Debug, S: Debug> Debug for Bimap<K, V, S>

Source§

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

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

impl<K, V, S> Default for Bimap<K, V, S>
where K: Eq + Hash + Clone, V: Eq + Hash + Clone, S: BuildHasher + Clone + Default,

Source§

fn default() -> Self

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

impl<K, V, S> FromIterator<(K, V)> for Bimap<K, V, S>
where K: Eq + Hash + Clone, V: Eq + Hash + Clone, S: BuildHasher + Clone + Default,

Source§

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

Creates a value from an iterator. Read more
Source§

impl<K, V, S> IntoIterator for Bimap<K, V, S>
where K: Eq + Hash + Clone, V: Eq + Hash + Clone, S: BuildHasher + Clone + Default,

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<K, V>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<K, V, S> Freeze for Bimap<K, V, S>
where S: Freeze,

§

impl<K, V, S> RefUnwindSafe for Bimap<K, V, S>

§

impl<K, V, S> Send for Bimap<K, V, S>
where S: Send, K: Send, V: Send,

§

impl<K, V, S> Sync for Bimap<K, V, S>
where S: Sync, K: Sync, V: Sync,

§

impl<K, V, S> Unpin for Bimap<K, V, S>
where S: Unpin, K: Unpin, V: Unpin,

§

impl<K, V, S> UnsafeUnpin for Bimap<K, V, S>
where S: UnsafeUnpin,

§

impl<K, V, S> UnwindSafe for Bimap<K, V, S>
where K: UnwindSafe, V: UnwindSafe, S: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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