Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. use std::{
  2. collections::{HashMap, HashSet},
  3. hash::Hash,
  4. };
  5.  
  6. pub trait HashLike<K, V>
  7. where
  8. K: Hash + Eq,
  9. {
  10. fn remove(&mut self, k: &K) -> Option<V>;
  11. }
  12.  
  13. #[derive(Debug)]
  14. pub struct MultiKeyMap<K, SK, V>
  15. where
  16. K: Hash + Eq,
  17. SK: Hash + Eq,
  18. {
  19. store: HashMap<K, V>,
  20. idx: HashMap<SK, HashSet<K>>,
  21. }
  22.  
  23. impl<K, SK, V> MultiKeyMap<K, SK, V>
  24. where
  25. K: Hash + Eq,
  26. for<'a> &'a K: IntoIterator<Item = &'a SK>,
  27. SK: Hash + Eq,
  28. {
  29. pub fn new() -> Self {
  30. MultiKeyMap {
  31. store: HashMap::new(),
  32. idx: HashMap::new(),
  33. }
  34. }
  35.  
  36. pub fn remove(&mut self, k: &K) -> Option<V> {
  37. for sk in k {
  38. /* do stuff */
  39. }
  40. None
  41. }
  42. }
  43.  
  44. impl<K, SK, V> HashLike<K, V> for MultiKeyMap<K, SK, V>
  45. where
  46. K: Hash + Eq + Clone,
  47. for<'a> &'a K: IntoIterator<Item = &'a SK>,
  48. SK: Hash + Eq + Clone,
  49. {
  50. fn remove(&mut self, k: &K) -> Option<V> {
  51. self.remove(k)
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement