use crate::misc::EasyUnwrapUnchecked;
pub const trait Map<K, V>: core::hash::Hash {
fn insert(&mut self, key_val: (K, V)) -> Option<V>;
fn get(&self, key: &K) -> Option<&V>;
fn get_mut(&mut self, key: &K) -> Option<&mut V>;
fn remove(&mut self, key: &K) -> Option<V>;
fn get_all(&self) -> Vec<(&K, &V)>;
fn find(&self, value: &V) -> Option<&K>;
fn index(&self, value: &V) -> Option<usize>;
fn get_at_index(&self, index: usize) -> Option<&V>;
fn get_at_index_mut(&mut self, index: usize) -> Option<&mut V>;
fn supports_indexing(&self) -> bool;
}
impl<K: core::hash::Hash + core::cmp::Ord, V: core::hash::Hash> Map<K, V>
for std::collections::BTreeMap<K, V>
{
fn insert(&mut self, key_val: (K, V)) -> Option<V> {
self.insert(key_val.0, key_val.1)
}
fn get(&self, key: &K) -> Option<&V> {
self.get(key)
}
fn get_mut(&mut self, key: &K) -> Option<&mut V> {
self.get_mut(key)
}
fn remove(&mut self, key: &K) -> Option<V> {
self.remove(key)
}
fn get_all(&self) -> Vec<(&K, &V)> {
let keys = self.keys();
let mut output = Vec::new();
for i in keys {
output.push((i, self.get(i).easy_unwrap_unchecked()));
}
output
}
fn find(&self, _value: &V) -> Option<&K> {
None
}
fn index(&self, _value: &V) -> Option<usize> {
None
}
fn get_at_index(&self, _index: usize) -> Option<&V> {
None
}
fn get_at_index_mut(&mut self, _index: usize) -> Option<&mut V> {
None
}
fn supports_indexing(&self) -> bool {
false
}
}