use crate::{
AtlasArtifact, BasisClassId, CertificateLimits, ClassCorrespondence, Diagram, EdgeKey,
ExplainedDiagram, IntervalGroupId, ReductionGuardKind, Result, RipsParams,
SparseDistanceMatrix,
};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProgramAtomInfo {
pub id: usize,
pub vertices: Vec<usize>,
pub edges: Vec<EdgeKey>,
pub separator_vertices: Vec<usize>,
pub cyclic: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ProgramSummary {
pub atoms: usize,
pub cyclic_atoms: usize,
pub articulation_vertices: usize,
pub zero_simplex_separators: usize,
pub widest_separator: usize,
pub separator_candidates_checked: usize,
pub separator_search_complete: bool,
pub largest_cyclic_atom_edges: usize,
pub complete_guards: usize,
pub guards: usize,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct ProgramWork {
pub edges_checked: usize,
pub h0_edges_scanned: usize,
pub guards_checked: usize,
pub atoms_touched: usize,
pub atoms_reused: usize,
pub atoms_repaired: usize,
pub atoms_rebuilt: usize,
pub reduction_columns_reused: usize,
pub reduction_columns_reduced: usize,
pub reduction_column_additions: usize,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum ProgramEventKind {
VertexSetChanged,
EdgeSetChanged,
ThresholdCrossing,
GuardFailed,
AtomRebuilt,
ReductionSuffixRepaired,
SeparatorContractChanged,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProgramEvent {
pub kind: ProgramEventKind,
pub atom: Option<usize>,
pub edge: Option<EdgeKey>,
pub guard: Option<ReductionGuardKind>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ProgramUpdateMode {
Reused,
Repaired,
Recompiled,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[non_exhaustive]
pub enum CorrespondenceMode {
#[default]
Exact,
Omit,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum ContinuationKind {
Isomorphism,
Split,
Merge,
Mixing,
Birth,
Death,
Ambiguous,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BasisTransport {
pub old: BasisClassId,
pub new: BasisClassId,
pub coefficient: u32,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ClassContinuation {
pub kind: ContinuationKind,
pub old_spaces: Vec<IntervalGroupId>,
pub new_spaces: Vec<IntervalGroupId>,
pub transport: Vec<BasisTransport>,
}
#[derive(Debug, Clone)]
pub struct ProgramEvaluation {
pub diagram: Diagram,
pub work: ProgramWork,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ProgramDiagramUpdateMode {
Reused,
Recompiled,
}
#[derive(Debug, Clone)]
pub struct ProgramDiagramUpdate {
pub diagram: Diagram,
pub mode: ProgramDiagramUpdateMode,
pub events: Vec<ProgramEvent>,
pub work: ProgramWork,
}
#[derive(Debug, Clone)]
pub struct ProgramUpdate {
pub result: ExplainedDiagram,
pub mode: ProgramUpdateMode,
pub events: Vec<ProgramEvent>,
pub continuation: Vec<ClassContinuation>,
pub correspondence: Vec<ClassCorrespondence>,
pub work: ProgramWork,
}
#[derive(Debug, Clone)]
pub struct ProgramCheckpoint {
pub(super) program: PersistenceProgram,
}
impl ProgramCheckpoint {
pub fn program(&self) -> &PersistenceProgram {
&self.program
}
pub fn branch(&self, alternatives: &[SparseDistanceMatrix]) -> Result<Vec<ProgramBranch>> {
self.program.branch(alternatives)
}
pub fn branch_with(
&self,
alternatives: &[SparseDistanceMatrix],
correspondence_mode: CorrespondenceMode,
) -> Result<Vec<ProgramBranch>> {
self.program.branch_with(alternatives, correspondence_mode)
}
}
#[derive(Debug, Clone)]
pub struct ProgramBranch {
pub index: usize,
pub update: ProgramUpdate,
pub(super) program: PersistenceProgram,
}
#[derive(Debug, Clone)]
pub struct ProgramDiagramState {
pub(super) program: PersistenceProgram,
pub(super) graph: SparseDistanceMatrix,
pub(super) diagram: Diagram,
pub(super) dirty: bool,
}
impl ProgramBranch {
pub fn program(&self) -> &PersistenceProgram {
&self.program
}
pub fn into_program(self) -> PersistenceProgram {
self.program
}
pub fn into_parts(self) -> (ProgramUpdate, PersistenceProgram) {
(self.update, self.program)
}
}
#[derive(Debug, Clone)]
pub(crate) struct ProgramAtomState {
pub(crate) info_index: usize,
pub(crate) vertices: Vec<usize>,
pub(crate) edges: Vec<EdgeKey>,
pub(crate) edge_positions: Vec<usize>,
pub(crate) artifact: AtlasArtifact,
pub(crate) certified_graph: SparseDistanceMatrix,
pub(crate) region: crate::CertifiedReductionRegion,
pub(crate) explained: ExplainedDiagram,
}
#[derive(Debug, Clone)]
pub struct PersistenceProgram {
pub(super) params: RipsParams,
pub(super) limits: CertificateLimits,
pub(super) graph: SparseDistanceMatrix,
pub(super) topology: Vec<EdgeKey>,
pub(super) active: Vec<bool>,
pub(super) separator_edges: Vec<EdgeKey>,
pub(super) h0_deaths: Vec<EdgeKey>,
pub(super) h0_essential: usize,
pub(super) atoms: Vec<ProgramAtomInfo>,
pub(super) states: Vec<ProgramAtomState>,
pub(super) summary: ProgramSummary,
pub(super) result: ExplainedDiagram,
}