lib-laddertypes/src/bimap.rs

26 lines
591 B
Rust
Raw Normal View History

2023-10-01 17:03:47 +02:00
use std::{collections::HashMap, hash::Hash};
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>\\
2023-10-01 17:03:47 +02:00
2024-10-06 14:38:41 +02:00
#[derive(Debug)]
2023-10-01 17:03:47 +02:00
pub struct Bimap<V: Eq + Hash, Λ: Eq + Hash> {
pub : HashMap<V, Λ>,
pub my: HashMap<Λ, V>,
}
impl<V: Eq + Hash + Clone, Λ: Eq + Hash + Clone> Bimap<V, Λ> {
pub fn new() -> Self {
Bimap {
: HashMap::new(),
my: HashMap::new(),
}
}
pub fn insert(&mut self, y: V, λ: Λ) {
self..insert(y.clone(), λ.clone());
self.my.insert(λ, y);
}
}
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>\\