Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::{
- collections::{HashMap, HashSet},
- hash::Hash,
- };
- pub trait HashLike<K, V>
- where
- K: Hash + Eq,
- {
- fn remove(&mut self, k: &K) -> Option<V>;
- }
- #[derive(Debug)]
- pub struct MultiKeyMap<K, SK, V>
- where
- K: Hash + Eq,
- SK: Hash + Eq,
- {
- store: HashMap<K, V>,
- idx: HashMap<SK, HashSet<K>>,
- }
- impl<K, SK, V> MultiKeyMap<K, SK, V>
- where
- K: Hash + Eq,
- for<'a> &'a K: IntoIterator<Item = &'a SK>,
- SK: Hash + Eq,
- {
- pub fn new() -> Self {
- MultiKeyMap {
- store: HashMap::new(),
- idx: HashMap::new(),
- }
- }
- pub fn remove(&mut self, k: &K) -> Option<V> {
- for sk in k {
- /* do stuff */
- }
- None
- }
- }
- impl<K, SK, V> HashLike<K, V> for MultiKeyMap<K, SK, V>
- where
- K: Hash + Eq + Clone,
- for<'a> &'a K: IntoIterator<Item = &'a SK>,
- SK: Hash + Eq + Clone,
- {
- fn remove(&mut self, k: &K) -> Option<V> {
- self.remove(k)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement