Struct comfy_wgpu::BiHashMap

pub struct BiHashMap<L, R, LS = RandomState, RS = RandomState> { /* private fields */ }
Expand description

A bimap backed by two HashMaps.

See the module-level documentation for more details and examples.

Implementations§

§

impl<L, R> BiHashMap<L, R, RandomState, RandomState>where L: Eq + Hash, R: Eq + Hash,

pub fn new() -> BiHashMap<L, R, RandomState, RandomState>

Creates an empty BiHashMap.

Examples
use bimap::BiHashMap;

let bimap = BiHashMap::<char, i32>::new();

pub fn with_capacity( capacity: usize ) -> BiHashMap<L, R, RandomState, RandomState>

Creates a new empty BiHashMap with the given capacity.

Examples
use bimap::BiHashMap;

let bimap = BiHashMap::<char, i32>::with_capacity(10);
assert!(bimap.capacity() >= 10);
§

impl<L, R, LS, RS> BiHashMap<L, R, LS, RS>where L: Eq + Hash, R: Eq + Hash,

pub fn len(&self) -> usize

Returns the number of left-right pairs in the bimap.

Examples
use bimap::BiHashMap;

let mut bimap = BiHashMap::new();
bimap.insert('a', 1);
bimap.insert('b', 2);
bimap.insert('c', 3);
assert_eq!(bimap.len(), 3);

pub fn is_empty(&self) -> bool

Returns true if the bimap contains no left-right pairs, and false otherwise.

Examples
use bimap::BiHashMap;

let mut bimap = BiHashMap::new();
assert!(bimap.is_empty());
bimap.insert('a', 1);
assert!(!bimap.is_empty());
bimap.remove_by_right(&1);
assert!(bimap.is_empty());

pub fn capacity(&self) -> usize

Returns a lower bound on the number of left-right pairs the BiHashMap can store without reallocating memory.

Examples
use bimap::BiHashMap;

let bimap = BiHashMap::<char, i32>::with_capacity(10);
assert!(bimap.capacity() >= 10);

pub fn clear(&mut self)

Removes all left-right pairs from the bimap.

Examples
use bimap::BiHashMap;

let mut bimap = BiHashMap::new();
bimap.insert('a', 1);
bimap.insert('b', 2);
bimap.insert('c', 3);
bimap.clear();
assert!(bimap.len() == 0);

pub fn iter(&self) -> Iter<'_, L, R>

Creates an iterator over the left-right pairs in the bimap in arbitrary order.

The iterator element type is (&L, &R).

Examples
use bimap::BiHashMap;

let mut bimap = BiHashMap::new();
bimap.insert('a', 1);
bimap.insert('b', 2);
bimap.insert('c', 3);

for (left, right) in bimap.iter() {
    println!("({}, {})", left, right);
}

pub fn left_values(&self) -> LeftValues<'_, L, R>

Creates an iterator over the left values in the bimap in arbitrary order.

The iterator element type is &L.

Examples
use bimap::BiHashMap;

let mut bimap = BiHashMap::new();
bimap.insert('a', 1);
bimap.insert('b', 2);
bimap.insert('c', 3);

for char_value in bimap.left_values() {
    println!("{}", char_value);
}

pub fn right_values(&self) -> RightValues<'_, L, R>

Creates an iterator over the right values in the bimap in arbitrary order.

The iterator element type is &R.

Examples
use bimap::BiHashMap;

let mut bimap = BiHashMap::new();
bimap.insert('a', 1);
bimap.insert('b', 2);
bimap.insert('c', 3);

for int_value in bimap.right_values() {
    println!("{}", int_value);
}
§

impl<L, R, LS, RS> BiHashMap<L, R, LS, RS>where L: Eq + Hash, R: Eq + Hash, LS: BuildHasher, RS: BuildHasher,

pub fn with_hashers( hash_builder_left: LS, hash_builder_right: RS ) -> BiHashMap<L, R, LS, RS>

Creates a new empty BiHashMap using hash_builder_left to hash left values and hash_builder_right to hash right values.

Examples
use std::collections::hash_map::RandomState;
use bimap::BiHashMap;

let s_left = RandomState::new();
let s_right = RandomState::new();
let mut bimap = BiHashMap::<char, i32>::with_hashers(s_left, s_right);
bimap.insert('a', 42);

pub fn with_capacity_and_hashers( capacity: usize, hash_builder_left: LS, hash_builder_right: RS ) -> BiHashMap<L, R, LS, RS>

Creates a new empty BiHashMap with the given capacity, using hash_builder_left to hash left values and hash_builder_right to hash right values.

Examples
use std::collections::hash_map::RandomState;
use bimap::BiHashMap;

let s_left = RandomState::new();
let s_right = RandomState::new();
let bimap = BiHashMap::<char, i32>::with_capacity_and_hashers(10, s_left, s_right);
assert!(bimap.capacity() >= 10);

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

Reserves capacity for at least additional more elements to be inserted in the BiHashMap. The collection may reserve more space to avoid frequent reallocations.

Panics

Panics if the new allocation size overflows usize.

Examples
use bimap::BiHashMap;

let mut bimap = BiHashMap::<char, i32>::new();
bimap.reserve(10);
assert!(bimap.capacity() >= 10);

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the bimap as much as possible. It will drop down as much as possible while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.

Examples
use bimap::BiHashMap;

let mut bimap = BiHashMap::<char, i32>::with_capacity(100);
bimap.insert('a', 1);
bimap.insert('b', 2);
assert!(bimap.capacity() >= 100);
bimap.shrink_to_fit();
assert!(bimap.capacity() >= 2);

pub fn shrink_to(&mut self, min_capacity: usize)

Shrinks the capacity of the bimap with a lower limit. It will drop down no lower than the supplied limit while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.

If the current capacity is less than the lower limit, this is a no-op.

Examples
use bimap::BiHashMap;

let mut bimap = BiHashMap::<char, i32>::with_capacity(100);
bimap.insert('a', 1);
bimap.insert('b', 2);
assert!(bimap.capacity() >= 100);
bimap.shrink_to(10);
assert!(bimap.capacity() >= 10);
bimap.shrink_to(0);
assert!(bimap.capacity() >= 2);

pub fn get_by_left<Q>(&self, left: &Q) -> Option<&R>where L: Borrow<Q>, Q: Eq + Hash + ?Sized,

Returns a reference to the right value corresponding to the given left value.

The input may be any borrowed form of the bimap’s left type, but Eq and Hash on the borrowed form must match those for the left type.

Examples
use bimap::BiHashMap;

let mut bimap = BiHashMap::new();
bimap.insert('a', 1);
assert_eq!(bimap.get_by_left(&'a'), Some(&1));
assert_eq!(bimap.get_by_left(&'z'), None);

pub fn get_by_right<Q>(&self, right: &Q) -> Option<&L>where R: Borrow<Q>, Q: Eq + Hash + ?Sized,

Returns a reference to the left value corresponding to the given right value.

The input may be any borrowed form of the bimap’s right type, but Eq and Hash on the borrowed form must match those for the right type.

Examples
use bimap::BiHashMap;

let mut bimap = BiHashMap::new();
bimap.insert('a', 1);
assert_eq!(bimap.get_by_right(&1), Some(&'a'));
assert_eq!(bimap.get_by_right(&2), None);

pub fn contains_left<Q>(&self, left: &Q) -> boolwhere L: Borrow<Q>, Q: Eq + Hash + ?Sized,

Returns true if the bimap contains the given left value and false otherwise.

The input may be any borrowed form of the bimap’s left type, but Eq and Hash on the borrowed form must match those for the left type.

Examples
use bimap::BiHashMap;

let mut bimap = BiHashMap::new();
bimap.insert('a', 1);
assert!(bimap.contains_left(&'a'));
assert!(!bimap.contains_left(&'b'));

pub fn contains_right<Q>(&self, right: &Q) -> boolwhere R: Borrow<Q>, Q: Eq + Hash + ?Sized,

Returns true if the map contains the given right value and false otherwise.

The input may be any borrowed form of the bimap’s right type, but Eq and Hash on the borrowed form must match those for the right type.

Examples
use bimap::BiHashMap;

let mut bimap = BiHashMap::new();
bimap.insert('a', 1);
assert!(bimap.contains_right(&1));
assert!(!bimap.contains_right(&2));

pub fn remove_by_left<Q>(&mut self, left: &Q) -> Option<(L, R)>where L: Borrow<Q>, Q: Eq + Hash + ?Sized,

Removes the left-right pair corresponding to the given left value.

Returns the previous left-right pair if the map contained the left value and None otherwise.

The input may be any borrowed form of the bimap’s left type, but Eq and Hash on the borrowed form must match those for the left type.

Examples
use bimap::BiHashMap;

let mut bimap = BiHashMap::new();
bimap.insert('a', 1);
bimap.insert('b', 2);
bimap.insert('c', 3);

assert_eq!(bimap.remove_by_left(&'b'), Some(('b', 2)));
assert_eq!(bimap.remove_by_left(&'b'), None);

pub fn remove_by_right<Q>(&mut self, right: &Q) -> Option<(L, R)>where R: Borrow<Q>, Q: Eq + Hash + ?Sized,

Removes the left-right pair corresponding to the given right value.

Returns the previous left-right pair if the map contained the right value and None otherwise.

The input may be any borrowed form of the bimap’s right type, but Eq and Hash on the borrowed form must match those for the right type.

Examples
use bimap::BiHashMap;

let mut bimap = BiHashMap::new();
bimap.insert('a', 1);
bimap.insert('b', 2);
bimap.insert('c', 3);

assert_eq!(bimap.remove_by_right(&2), Some(('b', 2)));
assert_eq!(bimap.remove_by_right(&2), None);

pub fn insert(&mut self, left: L, right: R) -> Overwritten<L, R>

Inserts the given left-right pair into the bimap.

Returns an enum Overwritten representing any left-right pairs that were overwritten by the call to insert. The example below details all possible enum variants that can be returned.

Warnings

Somewhat paradoxically, calling insert() can actually reduce the size of the bimap! This is because of the invariant that each left value maps to exactly one right value and vice versa.

Examples
use bimap::{BiHashMap, Overwritten};

let mut bimap = BiHashMap::new();
assert_eq!(bimap.len(), 0); // {}

// no values are overwritten.
assert_eq!(bimap.insert('a', 1), Overwritten::Neither);
assert_eq!(bimap.len(), 1); // {'a' <> 1}

// no values are overwritten.
assert_eq!(bimap.insert('b', 2), Overwritten::Neither);
assert_eq!(bimap.len(), 2); // {'a' <> 1, 'b' <> 2}

// ('a', 1) already exists, so inserting ('a', 4) overwrites 'a', the left value.
// the previous left-right pair ('a', 1) is returned.
assert_eq!(bimap.insert('a', 4), Overwritten::Left('a', 1));
assert_eq!(bimap.len(), 2); // {'a' <> 4, 'b' <> 2}

// ('b', 2) already exists, so inserting ('c', 2) overwrites 2, the right value.
// the previous left-right pair ('b', 2) is returned.
assert_eq!(bimap.insert('c', 2), Overwritten::Right('b', 2));
assert_eq!(bimap.len(), 2); // {'a' <> 1, 'c' <> 2}

// both ('a', 4) and ('c', 2) already exist, so inserting ('a', 2) overwrites both.
// ('a', 4) has the overwritten left value ('a'), so it's the first tuple returned.
// ('c', 2) has the overwritten right value (2), so it's the second tuple returned.
assert_eq!(bimap.insert('a', 2), Overwritten::Both(('a', 4), ('c', 2)));
assert_eq!(bimap.len(), 1); // {'a' <> 2} // bimap is smaller than before!

// ('a', 2) already exists, so inserting ('a', 2) overwrites the pair.
// the previous left-right pair ('a', 2) is returned.
assert_eq!(bimap.insert('a', 2), Overwritten::Pair('a', 2));
assert_eq!(bimap.len(), 1); // {'a' <> 2}

pub fn insert_no_overwrite(&mut self, left: L, right: R) -> Result<(), (L, R)>

Inserts the given left-right pair into the bimap without overwriting any existing values.

Returns Ok(()) if the pair was successfully inserted into the bimap. If either value exists in the map, Err((left, right) is returned with the attempted left-right pair and the map is unchanged.

Examples
use bimap::BiHashMap;

let mut bimap = BiHashMap::new();
assert_eq!(bimap.insert_no_overwrite('a', 1), Ok(()));
assert_eq!(bimap.insert_no_overwrite('b', 2), Ok(()));
assert_eq!(bimap.insert_no_overwrite('a', 3), Err(('a', 3)));
assert_eq!(bimap.insert_no_overwrite('c', 2), Err(('c', 2)));

pub fn retain<F>(&mut self, f: F)where F: FnMut(&L, &R) -> bool,

Retains only the elements specified by the predicate.

In other words, remove all left-right pairs (l, r) such that f(&l, &r) returns false.

Examples
use bimap::BiHashMap;

let mut bimap = BiHashMap::new();
bimap.insert('a', 1);
bimap.insert('b', 2);
bimap.insert('c', 3);
bimap.retain(|&l, &r| r >= 2);
assert_eq!(bimap.len(), 2);
assert_eq!(bimap.get_by_left(&'b'), Some(&2));
assert_eq!(bimap.get_by_left(&'c'), Some(&3));
assert_eq!(bimap.get_by_left(&'a'), None);

Trait Implementations§

§

impl<L, R, LS, RS> Clone for BiHashMap<L, R, LS, RS>where L: Clone + Eq + Hash, R: Clone + Eq + Hash, LS: BuildHasher + Clone, RS: BuildHasher + Clone,

§

fn clone(&self) -> BiHashMap<L, R, LS, RS>

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
§

impl<L, R, LS, RS> Debug for BiHashMap<L, R, LS, RS>where L: Debug, R: Debug,

§

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

Formats the value using the given formatter. Read more
§

impl<L, R, LS, RS> Default for BiHashMap<L, R, LS, RS>where L: Eq + Hash, R: Eq + Hash, LS: BuildHasher + Default, RS: BuildHasher + Default,

§

fn default() -> BiHashMap<L, R, LS, RS>

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

impl<L, R, LS, RS> Extend<(L, R)> for BiHashMap<L, R, LS, RS>where L: Eq + Hash, R: Eq + Hash, LS: BuildHasher, RS: BuildHasher,

§

fn extend<T>(&mut self, iter: T)where T: IntoIterator<Item = (L, R)>,

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
§

impl<L, R, LS, RS> FromIterator<(L, R)> for BiHashMap<L, R, LS, RS>where L: Eq + Hash, R: Eq + Hash, LS: BuildHasher + Default, RS: BuildHasher + Default,

§

fn from_iter<I>(iter: I) -> BiHashMap<L, R, LS, RS>where I: IntoIterator<Item = (L, R)>,

Creates a value from an iterator. Read more
§

impl<'a, L, R, LS, RS> IntoIterator for &'a BiHashMap<L, R, LS, RS>where L: Eq + Hash, R: Eq + Hash,

§

type Item = (&'a L, &'a R)

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, L, R>

Which kind of iterator are we turning this into?
§

fn into_iter(self) -> Iter<'a, L, R>

Creates an iterator from a value. Read more
§

impl<L, R, LS, RS> IntoIterator for BiHashMap<L, R, LS, RS>where L: Eq + Hash, R: Eq + Hash,

§

type Item = (L, R)

The type of the elements being iterated over.
§

type IntoIter = IntoIter<L, R>

Which kind of iterator are we turning this into?
§

fn into_iter(self) -> IntoIter<L, R>

Creates an iterator from a value. Read more
§

impl<L, R, LS, RS> PartialEq<BiHashMap<L, R, LS, RS>> for BiHashMap<L, R, LS, RS>where L: Eq + Hash, R: Eq + Hash, LS: BuildHasher, RS: BuildHasher,

§

fn eq(&self, other: &BiHashMap<L, R, LS, RS>) -> 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.
§

impl<L, R, LS, RS> Eq for BiHashMap<L, R, LS, RS>where L: Eq + Hash, R: Eq + Hash, LS: BuildHasher, RS: BuildHasher,

§

impl<L, R, LS, RS> Send for BiHashMap<L, R, LS, RS>where L: Send, R: Send, LS: Send, RS: Send,

§

impl<L, R, LS, RS> Sync for BiHashMap<L, R, LS, RS>where L: Sync, R: Sync, LS: Sync, RS: Sync,

Auto Trait Implementations§

§

impl<L, R, LS, RS> RefUnwindSafe for BiHashMap<L, R, LS, RS>where L: RefUnwindSafe, LS: RefUnwindSafe, R: RefUnwindSafe, RS: RefUnwindSafe,

§

impl<L, R, LS, RS> Unpin for BiHashMap<L, R, LS, RS>where LS: Unpin, RS: Unpin,

§

impl<L, R, LS, RS> UnwindSafe for BiHashMap<L, R, LS, RS>where L: RefUnwindSafe, LS: UnwindSafe, R: RefUnwindSafe, RS: 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> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

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.

§

impl<F, T> IntoSample<T> for Fwhere T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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
§

impl<T, U> ToSample<U> for Twhere U: FromSample<T>,

§

fn to_sample_(self) -> U

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

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> Any for Twhere T: Any,

§

impl<T> CloneAny for Twhere T: Any + Clone,

§

impl<T> Component for Twhere T: Send + Sync + 'static,

§

impl<S, T> Duplex<S> for Twhere T: FromSample<S> + ToSample<S>,

source§

impl<T> SerializableAny for Twhere T: 'static + Any + Clone + Send + Sync,