/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use std::collections::HashMap; /// A two-way hashmap. #[derive(Debug)] pub struct TwoWay { forward: HashMap, reverse: HashMap, } impl Default for TwoWay { fn default() -> Self { TwoWay { forward: Default::default(), reverse: Default::default(), } } } impl TwoWay { pub fn insert(&mut self, key: K, value: V) { self.forward.insert(key.clone(), value.clone()); self.reverse.insert(value, key); } pub fn forward(&self) -> &HashMap { &self.forward } pub fn reverse(&self) -> &HashMap { &self.reverse } }