51 lines
1.2 KiB
Rust
51 lines
1.2 KiB
Rust
//! Raw input relations with positional columns.
|
|
//!
|
|
//! Tables are the input to atom scans. They carry no column names: positions
|
|
//! are matched against an [`AtomPattern`](crate::atom::AtomPattern).
|
|
|
|
use crate::value::Value;
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct Table {
|
|
pub arity: usize,
|
|
pub rows: Vec<Vec<Value>>,
|
|
}
|
|
|
|
impl Table {
|
|
#[must_use]
|
|
pub fn new(arity: usize) -> Self {
|
|
Self {
|
|
arity,
|
|
rows: Vec::new(),
|
|
}
|
|
}
|
|
|
|
/// # Panics
|
|
/// Panics if any row's length differs from `arity`.
|
|
#[must_use]
|
|
pub fn from_rows(arity: usize, rows: Vec<Vec<Value>>) -> Self {
|
|
for (i, row) in rows.iter().enumerate() {
|
|
assert_eq!(
|
|
row.len(),
|
|
arity,
|
|
"row {i} arity mismatch: expected {arity}, got {}",
|
|
row.len(),
|
|
);
|
|
}
|
|
Self { arity, rows }
|
|
}
|
|
|
|
/// # Panics
|
|
/// Panics if `row.len() != self.arity`.
|
|
pub fn push(&mut self, row: Vec<Value>) {
|
|
assert_eq!(
|
|
row.len(),
|
|
self.arity,
|
|
"row arity mismatch: expected {}, got {}",
|
|
self.arity,
|
|
row.len(),
|
|
);
|
|
self.rows.push(row);
|
|
}
|
|
}
|