use std::collections::HashMap; use std::hash::Hash; pub struct HashList(HashMap>); impl core::fmt::Debug for HashList { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_tuple("HashList").field(&self.0).finish() } } impl Clone for HashList { fn clone(&self) -> Self { Self(self.0.clone()) } } impl HashList { pub fn new() -> Self { Self(HashMap::new()) } pub fn add(&mut self, key: K, value: V) { match self.0.get_mut(&key) { Some(values) => values.push(value), None => { self.0.insert(key, vec![value]); } } } pub fn decompose(&mut self) -> Box<[(K, Vec)]> { let mut body = HashMap::new(); core::mem::swap(&mut self.0, &mut body); body.into_iter().collect() } }