vortex_array/expr/pruning/
relation.rs1use std::hash::Hash;
5
6use vortex_utils::aliases::hash_map::{HashMap, IntoIter};
7use vortex_utils::aliases::hash_set::HashSet;
8
9#[derive(Debug, Clone)]
10pub struct Relation<K, V> {
11 map: HashMap<K, HashSet<V>>,
12}
13
14impl<K: Hash + Eq, V: Hash + Eq> Default for Relation<K, V> {
15 fn default() -> Self {
16 Self::new()
17 }
18}
19
20impl<K: Hash + Eq, V: Hash + Eq> Relation<K, V> {
21 pub fn new() -> Self {
22 Relation {
23 map: HashMap::new(),
24 }
25 }
26
27 pub fn insert(&mut self, k: K, v: V) {
28 self.map.entry(k).or_default().insert(v);
29 }
30
31 pub fn map(&self) -> &HashMap<K, HashSet<V>> {
32 &self.map
33 }
34}
35
36impl<K, V> From<HashMap<K, HashSet<V>>> for Relation<K, V> {
37 fn from(value: HashMap<K, HashSet<V>>) -> Self {
38 Self { map: value }
39 }
40}
41
42impl<K, V> IntoIterator for Relation<K, V> {
43 type Item = (K, HashSet<V>);
44 type IntoIter = IntoIter<K, HashSet<V>>;
45
46 fn into_iter(self) -> Self::IntoIter {
47 self.map.into_iter()
48 }
49}