Skip to main content

tablam/
row.rs

1use crate::for_impl::*;
2use crate::prelude::*;
3
4#[derive(Debug, Clone, Ord)]
5pub struct RowPk {
6    pub pk: usize,
7    pub data: Vec<Scalar>,
8}
9
10impl RowPk {
11    pub fn new(pk: usize, data: Vec<Scalar>) -> Self {
12        RowPk { pk, data }
13    }
14
15    pub fn pk(&self) -> &Scalar {
16        &self.data[self.pk]
17    }
18}
19
20impl PartialEq for RowPk {
21    fn eq(&self, other: &Self) -> bool {
22        self.data == other.data
23    }
24}
25impl Eq for RowPk {}
26
27impl Hash for RowPk {
28    fn hash<H: Hasher>(&self, state: &mut H) {
29        self.data.hash(state)
30    }
31}
32
33impl PartialOrd for RowPk {
34    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
35        Some(self.pk().cmp(&other.pk()))
36    }
37}
38
39pub fn fmt_row(row: &[Scalar], f: &mut fmt::Formatter<'_>) -> fmt::Result {
40    for (pos, x) in row.iter().enumerate() {
41        write!(f, " {}", x)?;
42        if pos < row.len() - 1 {
43            write!(f, ",")?;
44        }
45    }
46    Ok(())
47}
48
49impl fmt::Display for RowPk {
50    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51        fmt_row(&self.data, f)
52    }
53}