use std::{ collections::HashMap, hash::{BuildHasher, Hash}, }; use const_lru::ConstLru; use num_traits::{PrimInt, Unsigned}; use super::utils::boxed_const_lru; pub trait Get { fn get_by_key(&mut self, k: &K) -> Option<&V>; } impl Get for HashMap { fn get_by_key(&mut self, k: &K) -> Option<&V> { self.get(k) } } impl Get for ConstLru { fn get_by_key(&mut self, k: &K) -> Option<&V> { self.get(k) } } impl Get for Box> { fn get_by_key(&mut self, k: &K) -> Option<&V> { self.get(k) } } pub trait Insert { fn insert_no_ret(&mut self, k: K, v: V); } impl Insert for HashMap { fn insert_no_ret(&mut self, k: K, v: V) { self.insert(k, v); } } impl Insert for ConstLru { fn insert_no_ret(&mut self, k: K, v: V) { self.insert(k, v); } } impl Insert for Box> { fn insert_no_ret(&mut self, k: K, v: V) { self.insert(k, v); } } pub trait Remove { fn remove_by_key(&mut self, k: &K) -> Option; } impl Remove for HashMap { fn remove_by_key(&mut self, k: &K) -> Option { self.remove(k) } } impl Remove for ConstLru { fn remove_by_key(&mut self, k: &K) -> Option { self.remove(k) } } impl Remove for Box> { fn remove_by_key(&mut self, k: &K) -> Option { self.remove(k) } } pub trait CreateNew { fn create_new() -> Self; } impl CreateNew for HashMap { fn create_new() -> Self { Self::new() } } impl CreateNew for ConstLru { fn create_new() -> Self { Self::new() } } impl CreateNew for Box> { fn create_new() -> Self { boxed_const_lru() } }