#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct CatalogAtlasLimits {
pub max_pairs: usize,
pub max_ext_cells: usize,
pub max_resolution_terms: usize,
pub max_materialized_summands: usize,
pub max_materialized_cells: usize,
}
impl Default for CatalogAtlasLimits {
fn default() -> Self {
Self {
max_pairs: 1_000_000,
max_ext_cells: 10_000_000,
max_resolution_terms: 10_000_000,
max_materialized_summands: 1_000_000,
max_materialized_cells: 10_000_000,
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum CatalogAtlasError {
DegreeOverflow { degree: usize },
PairCountOverflow { catalog_len: usize },
ExtCellCountOverflow { pairs: usize, degrees: usize },
ResolutionTermOverflow { terms_per_source: usize },
ResolutionCountOverflow {
sources: usize,
terms_per_source: usize,
},
PairLimit { requested: usize, limit: usize },
ExtCellLimit { requested: usize, limit: usize },
ResolutionTermLimit { requested: usize, limit: usize },
}
display_error! { error CatalogAtlasError {
Self::DegreeOverflow { degree } => "Ext degree {degree} has no representable successor";
Self::PairCountOverflow { catalog_len } => "the catalog pair count overflows for {catalog_len} entries";
Self::ExtCellCountOverflow { pairs, degrees } => "the Ext-cell count overflows for {pairs} pairs and {degrees} degrees";
Self::ResolutionTermOverflow { terms_per_source } => "one source resolution needs {terms_per_source} terms, but that count overflows";
Self::ResolutionCountOverflow { sources, terms_per_source } => "the resolution-term count overflows for {sources} sources and {terms_per_source} terms per source";
Self::PairLimit { requested, limit } => "the catalog atlas needs {requested} ordered pairs, above the limit {limit}";
Self::ExtCellLimit { requested, limit } => "the catalog atlas needs {requested} Ext cells, above the limit {limit}";
Self::ResolutionTermLimit { requested, limit } => "the catalog atlas needs {requested} resolution terms, above the limit {limit}";
} }
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct CatalogAtlasWork {
pub pairs: usize,
pub ext_cells: usize,
pub resolutions: usize,
pub resolution_terms: usize,
pub ext_tables: usize,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CatalogExtRow {
source: usize,
target: usize,
dimensions: Vec<usize>,
}
impl CatalogExtRow {
pub(crate) fn new(source: usize, target: usize, dimensions: Vec<usize>) -> Self {
Self {
source,
target,
dimensions,
}
}
accessor_methods! {
pub source() -> usize = |this| this.source;
pub target() -> usize = |this| this.target;
pub dimensions() -> &[usize] = |this| &this.dimensions;
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CatalogExtTable {
catalog_len: usize,
max_degree: usize,
rows: Vec<CatalogExtRow>,
}
impl CatalogExtTable {
pub(crate) fn new(catalog_len: usize, max_degree: usize, rows: Vec<CatalogExtRow>) -> Self {
Self {
catalog_len,
max_degree,
rows,
}
}
accessor_methods! {
pub catalog_len() -> usize = |this| this.catalog_len;
pub max_degree() -> usize = |this| this.max_degree;
pub rows() -> &[CatalogExtRow] = |this| &this.rows;
pub len() -> usize = |this| this.rows.len();
pub is_empty() -> bool = |this| this.rows.is_empty();
}
pub fn row(&self, source: usize, target: usize) -> Option<&CatalogExtRow> {
let index = source
.checked_mul(self.catalog_len)
.and_then(|offset| offset.checked_add(target))?;
(source < self.catalog_len && target < self.catalog_len).then(|| &self.rows[index])
}
pub fn dimensions(&self, source: usize, target: usize) -> Option<&[usize]> {
self.row(source, target).map(CatalogExtRow::dimensions)
}
pub fn dim(&self, source: usize, target: usize, degree: usize) -> Option<usize> {
self.dimensions(source, target)
.and_then(|dimensions| dimensions.get(degree).copied())
}
}
pub type MultiplicityVector = Vec<usize>;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct MultiplicityLimits {
pub max_solutions: usize,
pub max_nodes: usize,
}
impl Default for MultiplicityLimits {
fn default() -> Self {
Self {
max_solutions: 1_000_000,
max_nodes: 10_000_000,
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum MultiplicityError {
DimensionVectorLength { expected: usize, got: usize },
NodeCountOverflow,
NodeStackAllocationFailed { requested: usize },
}
display_error! { error MultiplicityError {
Self::DimensionVectorLength { expected, got } => "target dimension vector has {got} entries, expected {expected}";
Self::NodeCountOverflow => "multiplicity search node count overflows usize";
Self::NodeStackAllocationFailed { requested } => "multiplicity search stack allocation failed for {requested} entries";
} }
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum AtlasMaterializeError {
MultiplicityLength { expected: usize, got: usize },
SummandLimit { requested: usize, limit: usize },
SummandCountOverflow,
DimensionProductOverflow {
index: usize,
vertex: usize,
multiplicity: usize,
dimension: usize,
},
DimensionSumOverflow { vertex: usize },
TotalDimensionOverflow,
CellProductOverflow { rows: usize, columns: usize },
CellCountOverflow,
CellLimit { requested: usize, limit: usize },
AllocationFailed { requested: usize },
}
display_error! { error AtlasMaterializeError {
Self::MultiplicityLength { expected, got } => "multiplicity vector has {got} entries, expected {expected}";
Self::SummandLimit { requested, limit } => "direct-sum request needs {requested} summands, above the limit {limit}";
Self::SummandCountOverflow => "direct-sum summand count overflows usize";
Self::DimensionProductOverflow { index, vertex, multiplicity, dimension } => "multiplicity {multiplicity} at catalog index {index} overflows dimension {dimension} at vertex {vertex}";
Self::DimensionSumOverflow { vertex } => "direct-sum dimension overflows at vertex {vertex}";
Self::TotalDimensionOverflow => "direct-sum total dimension overflows usize";
Self::CellProductOverflow { rows, columns } => "materialized matrix shape {rows}x{columns} overflows its cell count";
Self::CellCountOverflow => "materialized matrix cell count overflows usize";
Self::CellLimit { requested, limit } => "materialized matrices need {requested} cells, above the limit {limit}";
Self::AllocationFailed { requested } => "direct-sum reference list allocation failed for {requested} summands";
} }