36 lines
801 B
Rust
36 lines
801 B
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 `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);
|
||
|
|
}
|
||
|
|
}
|