Struct bimap::btree::BiBTreeMap [−][src]
A bimap backed by two BTreeMap
s.
See the module-level documentation for more details and examples.
Implementations
impl<L, R> BiBTreeMap<L, R> where
L: Ord,
R: Ord,
[src]
L: Ord,
R: Ord,
pub fn new() -> Self
[src]
Creates an empty BiBTreeMap
.
Examples
use bimap::BiBTreeMap; let bimap = BiBTreeMap::<char, i32>::new();
pub fn len(&self) -> usize
[src]
Returns the number of left-right pairs in the bimap.
Examples
use bimap::BiBTreeMap; let mut bimap = BiBTreeMap::new(); bimap.insert('a', 1); bimap.insert('b', 2); bimap.insert('c', 3); assert_eq!(bimap.len(), 3);
pub fn is_empty(&self) -> bool
[src]
Returns true
if the bimap contains no left-right pairs, and false
otherwise.
Examples
use bimap::BiBTreeMap; let mut bimap = BiBTreeMap::new(); assert!(bimap.is_empty()); bimap.insert('a', 1); assert!(!bimap.is_empty()); bimap.remove_by_right(&1); assert!(bimap.is_empty());
pub fn clear(&mut self)
[src]
Removes all left-right pairs from the bimap.
Examples
use bimap::BiBTreeMap; let mut bimap = BiBTreeMap::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>ⓘ
[src]
Creates an iterator over the left-right pairs in the bimap in ascending order by left value.
The iterator element type is (&L, &R)
.
Examples
use bimap::BiBTreeMap; let mut bimap = BiBTreeMap::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>ⓘNotable traits for LeftValues<'a, L, R>
impl<'a, L, R> Iterator for LeftValues<'a, L, R> type Item = &'a L;
[src]
Notable traits for LeftValues<'a, L, R>
impl<'a, L, R> Iterator for LeftValues<'a, L, R> type Item = &'a L;
Creates an iterator over the left values in the bimap in ascending order.
The iterator element type is &L
.
Examples
use bimap::BiBTreeMap; let mut bimap = BiBTreeMap::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>ⓘNotable traits for RightValues<'a, L, R>
impl<'a, L, R> Iterator for RightValues<'a, L, R> type Item = &'a R;
[src]
Notable traits for RightValues<'a, L, R>
impl<'a, L, R> Iterator for RightValues<'a, L, R> type Item = &'a R;
Creates an iterator over the right values in the bimap in ascending order.
The iterator element type is &R
.
Examples
use bimap::BiBTreeMap; let mut bimap = BiBTreeMap::new(); bimap.insert('a', 1); bimap.insert('b', 2); bimap.insert('c', 3); for int_value in bimap.right_values() { println!("{}", int_value); }
pub fn get_by_left<Q: ?Sized>(&self, left: &Q) -> Option<&R> where
L: Borrow<Q>,
Q: Ord,
[src]
L: Borrow<Q>,
Q: Ord,
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 the ordering on the borrowed form must match the ordering on the left type.
Examples
use bimap::BiBTreeMap; let mut bimap = BiBTreeMap::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: ?Sized>(&self, right: &Q) -> Option<&L> where
R: Borrow<Q>,
Q: Ord,
[src]
R: Borrow<Q>,
Q: Ord,
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 the ordering on the borrowed form must match the ordering on the right type.
Examples
use bimap::BiBTreeMap; let mut bimap = BiBTreeMap::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: ?Sized>(&self, left: &Q) -> bool where
L: Borrow<Q>,
Q: Ord,
[src]
L: Borrow<Q>,
Q: Ord,
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 the ordering on the borrowed form must match the ordering on the left type.
Examples
use bimap::BiBTreeMap; let mut bimap = BiBTreeMap::new(); bimap.insert('a', 1); assert!(bimap.contains_left(&'a')); assert!(!bimap.contains_left(&'b'));
pub fn contains_right<Q: ?Sized>(&self, right: &Q) -> bool where
R: Borrow<Q>,
Q: Ord,
[src]
R: Borrow<Q>,
Q: Ord,
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 the ordering on the borrowed form must match the ordering on the right type.
Examples
use bimap::BiBTreeMap; let mut bimap = BiBTreeMap::new(); bimap.insert('a', 1); assert!(bimap.contains_right(&1)); assert!(!bimap.contains_right(&2));
pub fn remove_by_left<Q: ?Sized>(&mut self, left: &Q) -> Option<(L, R)> where
L: Borrow<Q>,
Q: Ord,
[src]
L: Borrow<Q>,
Q: Ord,
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 the ordering on the borrowed form must match the ordering on the left type.
Examples
use bimap::BiBTreeMap; let mut bimap = BiBTreeMap::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: ?Sized>(&mut self, right: &Q) -> Option<(L, R)> where
R: Borrow<Q>,
Q: Ord,
[src]
R: Borrow<Q>,
Q: Ord,
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 the ordering on the borrowed form must match the ordering on the right type.
Examples
use bimap::BiBTreeMap; let mut bimap = BiBTreeMap::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>
[src]
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::{BiBTreeMap, Overwritten}; let mut bimap = BiBTreeMap::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)>
[src]
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::BiBTreeMap; let mut bimap = BiBTreeMap::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 left_range<T: ?Sized, A>(&self, range: A) -> LeftRange<'_, L, R>ⓘ where
L: Borrow<T>,
A: RangeBounds<T>,
T: Ord,
[src]
L: Borrow<T>,
A: RangeBounds<T>,
T: Ord,
Creates an iterator over the left-right pairs lying within a range of left values in the bimap in ascending order by left.
The iterator element type is (&L, &R)
.
The range bounds may be any borrowed form of the bimap’s left type, but the ordering on the borrowed form must match the ordering on the left type.
Examples
use bimap::BiBTreeMap; let mut bimap = BiBTreeMap::new(); bimap.insert('a', 1); bimap.insert('b', 2); bimap.insert('c', 3); bimap.insert('d', 4); for (left, right) in bimap.left_range('b'..'d') { println!("({}, {})", left, right); }
pub fn right_range<T: ?Sized, A>(&self, range: A) -> RightRange<'_, L, R>ⓘNotable traits for RightRange<'a, L, R>
impl<'a, L, R> Iterator for RightRange<'a, L, R> type Item = (&'a L, &'a R);
where
R: Borrow<T>,
A: RangeBounds<T>,
T: Ord,
[src]
Notable traits for RightRange<'a, L, R>
impl<'a, L, R> Iterator for RightRange<'a, L, R> type Item = (&'a L, &'a R);
R: Borrow<T>,
A: RangeBounds<T>,
T: Ord,
Creates an iterator over the left-right pairs lying within a range of right values in the bimap in ascending order by right.
The iterator element type is (&L, &R)
.
The range bounds may be any borrowed form of the bimap’s right type, but the ordering on the borrowed form must match the ordering on the right type.
Examples
use bimap::BiBTreeMap; let mut bimap = BiBTreeMap::new(); bimap.insert('a', 1); bimap.insert('b', 2); bimap.insert('c', 3); bimap.insert('d', 4); for (left, right) in bimap.right_range(2..4) { println!("({}, {})", left, right); }
Trait Implementations
impl<L, R> Clone for BiBTreeMap<L, R> where
L: Clone + Ord,
R: Clone + Ord,
[src]
L: Clone + Ord,
R: Clone + Ord,
fn clone(&self) -> BiBTreeMap<L, R>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<L, R> Debug for BiBTreeMap<L, R> where
L: Debug + Ord,
R: Debug + Ord,
[src]
L: Debug + Ord,
R: Debug + Ord,
impl<L, R> Default for BiBTreeMap<L, R> where
L: Ord,
R: Ord,
[src]
L: Ord,
R: Ord,
fn default() -> BiBTreeMap<L, R>
[src]
impl<'de, L, R> Deserialize<'de> for BiBTreeMap<L, R> where
L: Deserialize<'de> + Ord,
R: Deserialize<'de> + Ord,
[src]
L: Deserialize<'de> + Ord,
R: Deserialize<'de> + Ord,
Deserializer for BiBTreeMap
fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, D::Error>
[src]
impl<L, R> Eq for BiBTreeMap<L, R> where
L: Ord,
R: Ord,
[src]
L: Ord,
R: Ord,
impl<L, R> Extend<(L, R)> for BiBTreeMap<L, R> where
L: Ord,
R: Ord,
[src]
L: Ord,
R: Ord,
fn extend<T: IntoIterator<Item = (L, R)>>(&mut self, iter: T)
[src]
pub fn extend_one(&mut self, item: A)
[src]
pub fn extend_reserve(&mut self, additional: usize)
[src]
impl<L, R> FromIterator<(L, R)> for BiBTreeMap<L, R> where
L: Ord,
R: Ord,
[src]
L: Ord,
R: Ord,
fn from_iter<I>(iter: I) -> BiBTreeMap<L, R> where
I: IntoIterator<Item = (L, R)>,
[src]
I: IntoIterator<Item = (L, R)>,
impl<L, R> Hash for BiBTreeMap<L, R> where
L: Hash,
R: Hash,
[src]
L: Hash,
R: Hash,
fn hash<H: Hasher>(&self, state: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'a, L, R> IntoIterator for &'a BiBTreeMap<L, R> where
L: Ord,
R: Ord,
[src]
L: Ord,
R: Ord,
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>ⓘ
[src]
impl<L, R> IntoIterator for BiBTreeMap<L, R> where
L: Ord,
R: Ord,
[src]
L: Ord,
R: Ord,
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>ⓘ
[src]
impl<L, R> Ord for BiBTreeMap<L, R> where
L: Ord,
R: Ord,
[src]
L: Ord,
R: Ord,
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<L, R> PartialEq<BiBTreeMap<L, R>> for BiBTreeMap<L, R> where
L: Ord,
R: Ord,
[src]
L: Ord,
R: Ord,
impl<L, R> PartialOrd<BiBTreeMap<L, R>> for BiBTreeMap<L, R> where
L: Ord,
R: Ord,
[src]
L: Ord,
R: Ord,
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<L, R> Send for BiBTreeMap<L, R> where
L: Send,
R: Send,
[src]
L: Send,
R: Send,
impl<L, R> Serialize for BiBTreeMap<L, R> where
L: Serialize + Ord,
R: Serialize + Ord,
[src]
L: Serialize + Ord,
R: Serialize + Ord,
Serializer for BiBTreeMap
impl<L, R> Sync for BiBTreeMap<L, R> where
L: Sync,
R: Sync,
[src]
L: Sync,
R: Sync,
Auto Trait Implementations
impl<L, R> !RefUnwindSafe for BiBTreeMap<L, R>
impl<L, R> Unpin for BiBTreeMap<L, R>
impl<L, R> !UnwindSafe for BiBTreeMap<L, R>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,