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>
impl<K1, K2, V> MultikeyBTreeMap<K1, K2, V>
Sourcepub fn get<Q>(&self, key: &Q) -> Option<&V>
pub fn get<Q>(&self, key: &Q) -> Option<&V>
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`.
Sourcepub fn get_alt<Q2>(&self, key: &Q2) -> Option<&V>
pub fn get_alt<Q2>(&self, key: &Q2) -> Option<&V>
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.
Sourcepub fn insert(&mut self, k1: K1, k2: K2, v: V) -> Option<V>
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.