pub struct BijectiveMap<KT, VT, const CAP: usize = 16> { /* private fields */ }Expand description
This is your bijective map struct
Implementations§
Source§impl<KT: Hash + Eq, VT: Hash + Eq, const CAP: usize> BijectiveMap<KT, VT, CAP>
impl<KT: Hash + Eq, VT: Hash + Eq, const CAP: usize> BijectiveMap<KT, VT, CAP>
Sourcepub fn get_by_key(&mut self, key: &KT) -> Option<&VT>
pub fn get_by_key(&mut self, key: &KT) -> Option<&VT>
Returns a immutable reference to the value corresponding to
the given key, if it exists. Note that there can’t be a
Option<&mut T> version of this method because changing the
value will require adjusting other associations in the map.
This function has been completed and you can consult its source
as hint.
Source§impl<KT: Hash + Eq, VT: Hash + Eq, const CAP: usize> BijectiveMap<KT, VT, CAP>
Place all your code in another impl block, and fully implement the
methods BijectiveMap::get_by_val, BijectiveMap::take_by_key,
BijectiveMap::take_by_val, and BijectiveMap::set.
impl<KT: Hash + Eq, VT: Hash + Eq, const CAP: usize> BijectiveMap<KT, VT, CAP>
Place all your code in another impl block, and fully implement the methods BijectiveMap::get_by_val, BijectiveMap::take_by_key, BijectiveMap::take_by_val, and BijectiveMap::set.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns number of key-value pairs in this map. This one’s too easy so I just did it for you again. I will give away more stuff if you come to me for help …
Sourcepub fn get_by_val(&mut self, val: &VT) -> Option<&KT>
pub fn get_by_val(&mut self, val: &VT) -> Option<&KT>
This is the first method you need to implement.
Returns an immutable reference to the key associated with the
given value, if it exists. The dummy provided here just returns
None and you need to rewrite it appropriately.
Sourcepub fn take_by_key(&mut self, key: &KT) -> Option<(KT, VT)>
pub fn take_by_key(&mut self, key: &KT) -> Option<(KT, VT)>
This is another method you need to implement.
Removes key-value pair from map by searching for it by key.
Returns the key and value if found. Note that this function
is “take” and not “get” because it moves the actual key and value
out of the map. It doesn’t return references. Sometimes you
may need to convert an Option<T> to an Option<&T>. To do
that, given such an Option<T> opt, use the expression opt.as_ref().
The dummy implemenetation provided here just returns None
Sourcepub fn take_by_val(&mut self, val: &VT) -> Option<(KT, VT)>
pub fn take_by_val(&mut self, val: &VT) -> Option<(KT, VT)>
Dummies always return None. Are you a dummy?
Sourcepub fn set(&mut self, key: KT, val: VT) -> Option<(KT, VT)>
pub fn set(&mut self, key: KT, val: VT) -> Option<(KT, VT)>
Change or add key-val pair, return a pair to represent information that was deleted. Note that the returned key,value, if they exist, may indicate a different key or value that existed in the map before the change (see “daynum” example that you should replicate in main). Replace the dummy implementation.