Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 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<'a, 'b, K, SK, V> MultiKeyMap<K, SK, V>
  24. where
  25. K: Hash + Eq + 'a,
  26. 'b: 'a,
  27. &'a K: IntoIterator<Item = &'b SK>,
  28. SK: Hash + Eq + 'b,
  29. {
  30. pub fn new() -> Self {
  31. MultiKeyMap {
  32. store: HashMap::new(),
  33. idx: HashMap::new(),
  34. }
  35. }
  36.  
  37. pub fn remove(&mut self, k: &'a K) -> Option<V> {
  38. for sk in k {
  39. /* do stuff */
  40. }
  41. None
  42. }
  43. }
  44.  
  45. impl<'a, 'b, K, SK, V> HashLike<K, V> for MultiKeyMap<K, SK, V>
  46. where
  47. K: Hash + Eq + Clone + 'a,
  48. 'b: 'a,
  49. &'a K: IntoIterator<Item = &'b SK>,
  50. SK: Hash + Eq + Clone + 'b,
  51. {
  52. fn remove(&mut self, k: &K) -> Option<V> {
  53. self.remove(k)
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement