1use std::collections::HashMap;
2
3use kimchi::circuits::expr::{CacheId, FormattedOutput};
4
5#[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)]
7pub enum Column<T> {
8 Relation(T),
10 DynamicSelector(usize),
12 FixedSelector(usize),
14 LookupPartialSum((u32, usize)),
18 LookupMultiplicity((u32, usize)),
21 LookupAggregation,
23 LookupFixedTable(u32),
25}
26
27impl Column<usize> {
28 pub fn add_rel_offset(self, offset: usize) -> Column<usize> {
30 let Column::Relation(i) = self else {
31 todo!("add_rel_offset is only implemented for the relation columns")
32 };
33 Column::Relation(offset + i)
34 }
35}
36
37impl FormattedOutput for Column<usize> {
38 fn latex(&self, _cache: &mut HashMap<CacheId, Self>) -> String {
39 match self {
40 Column::Relation(i) => format!("x_{{{i}}}"),
41 Column::FixedSelector(i) => format!("fs_{{{i}}}"),
42 Column::DynamicSelector(i) => format!("ds_{{{i}}}"),
43 Column::LookupPartialSum((table_id, i)) => format!("h_{{{table_id}, {i}}}"),
44 Column::LookupMultiplicity((table_id, i)) => format!("m_{{{table_id}, {i}}}"),
45 Column::LookupFixedTable(i) => format!("t_{{{i}}}"),
46 Column::LookupAggregation => String::from("φ"),
47 }
48 }
49
50 fn text(&self, _cache: &mut HashMap<CacheId, Self>) -> String {
51 match self {
52 Column::Relation(i) => format!("x[{i}]"),
53 Column::FixedSelector(i) => format!("fs[{i}]"),
54 Column::DynamicSelector(i) => format!("ds[{i}]"),
55 Column::LookupPartialSum((table_id, i)) => format!("h[{table_id}, {i}]"),
56 Column::LookupMultiplicity((table_id, i)) => format!("m[{table_id}, {i}]"),
57 Column::LookupFixedTable(i) => format!("t[{i}]"),
58 Column::LookupAggregation => String::from("φ"),
59 }
60 }
61
62 fn ocaml(&self, _cache: &mut HashMap<CacheId, Self>) -> String {
63 unimplemented!("Not used at the moment")
65 }
66
67 fn is_alpha(&self) -> bool {
68 unimplemented!("Not used at the moment")
70 }
71}
72
73pub trait ColumnIndexer<T>: core::fmt::Debug + Copy + Eq + Ord {
76 const N_COL: usize;
78
79 fn to_column(self) -> Column<T>;
81}