pub struct MultikeyBTreeMap<K1, K2, V> {
    main: BTreeMap<K1, (K2, V)>,
    alt: BTreeMap<K2, K1>,
}
Expand description

A BTreeMap that supports 2 types of keys per value. All the usual restrictions and warnings for std::collections::BTreeMap also apply to this struct. Additionally, there is a 1:1 relationship between the 2 key types. In other words, for each K1 in the map, there is exactly one K2 in the map and vice versa.

Fields§

§main: BTreeMap<K1, (K2, V)>§alt: BTreeMap<K2, K1>

Implementations§

source§

impl<K1, K2, V> MultikeyBTreeMap<K1, K2, V>
where K1: Clone + Ord, K2: Clone + Ord,

source

pub fn new() -> Self

Create a new empty MultikeyBTreeMap.

source

pub fn get<Q>(&self, key: &Q) -> Option<&V>
where K1: Borrow<Q>, Q: Ord + ?Sized,

Returns a reference to the value corresponding to the key.

The key may be any borrowed form of K1``, but the ordering on the borrowed form must match the ordering on K1`.

source

pub fn get_alt<Q2>(&self, key: &Q2) -> Option<&V>
where K2: Borrow<Q2>, Q2: Ord + ?Sized,

Returns a reference to the value corresponding to the alternate key.

The key may be any borrowed form of the K2``, but the ordering on the borrowed form must match the ordering on K2`.

Note that this method performs 2 lookups: one to get the main key and another to get the value associated with that key. For best performance callers should prefer the get method over this method whenever possible as get only needs to perform one lookup.

source

pub fn insert(&mut self, k1: K1, k2: K2, v: V) -> Option<V>

Inserts a new entry into the map with the given keys and value.

Returns None if the map did not have an entry with k1 or k2 present. If exactly one key was present, then the value associated with that key is updated, the other key is removed, and the old value is returned. If both keys were present then the value associated with the main key is updated, the value associated with the alternate key is removed, and the old value associated with the main key is returned.

source

pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
where K1: Borrow<Q>, Q: Ord + ?Sized,

Remove a key from the map, returning the value associated with that key if it was previously in the map.

The key may be any borrowed form of K1``, but the ordering on the borrowed form must match the ordering on K1`.

source

pub fn clear(&mut self)

Clears the map, removing all values.

Auto Trait Implementations§

§

impl<K1, K2, V> RefUnwindSafe for MultikeyBTreeMap<K1, K2, V>

§

impl<K1, K2, V> Send for MultikeyBTreeMap<K1, K2, V>
where K1: Send, K2: Send, V: Send,

§

impl<K1, K2, V> Sync for MultikeyBTreeMap<K1, K2, V>
where K1: Sync, K2: Sync, V: Sync,

§

impl<K1, K2, V> Unpin for MultikeyBTreeMap<K1, K2, V>

§

impl<K1, K2, V> UnwindSafe for MultikeyBTreeMap<K1, K2, V>

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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, U> TryFrom<U> for T
where 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 T
where 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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V