use std::collections::{BTreeMap, HashMap};
use std::hash::{Hash, BuildHasher};
pub trait Map {
type Key;
type Value;
fn new() -> Self;
fn with_capacity(usize) -> Self;
fn len(&self) -> usize;
fn insert(&mut self, Self::Key, Self::Value) -> Option<Self::Value>;
fn get(&self, Self::Key) -> Option<&Self::Value>;
fn remove(&mut self, Self::Key) -> Option<Self::Value>;
fn shrink_to_fit(&mut self);
}
impl<K: Eq + Hash, V, H: Default + BuildHasher> Map for HashMap<K, V, H> {
type Key = K;
type Value = V;
fn new() -> Self {
HashMap::default()
}
fn with_capacity(capacity: usize) -> Self {
HashMap::with_capacity_and_hasher(capacity, Default::default())
}
fn len(&self) -> usize {
self.len()
}
fn insert(&mut self, k: K, v: V) -> Option<V> {
self.insert(k, v)
}
fn get(&self, k: K) -> Option<&V> {
self.get(&k)
}
fn remove(&mut self, k: K) -> Option<V> {
self.remove(&k)
}
fn shrink_to_fit(&mut self) {
self.shrink_to_fit();
}
}
impl<K: Eq + Ord, V> Map for BTreeMap<K, V> {
type Key = K;
type Value = V;
fn new() -> Self {
BTreeMap::new()
}
fn with_capacity(_: usize) -> Self {
BTreeMap::new()
}
fn len(&self) -> usize {
self.len()
}
fn insert(&mut self, k: K, v: V) -> Option<V> {
self.insert(k, v)
}
fn get(&self, k: K) -> Option<&V> {
self.get(&k)
}
fn remove(&mut self, k: K) -> Option<V> {
self.remove(&k)
}
fn shrink_to_fit(&mut self) {}
}