use core::time::Duration;
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct ProgressSnapshot {
pub(crate) revision: u64,
pub(crate) input_bits: usize,
pub(crate) phase: ProgressPhase,
pub(crate) amount: ProgressAmount,
}
impl ProgressSnapshot {
pub const fn revision(&self) -> u64 {
self.revision
}
pub const fn input_bits(&self) -> usize {
self.input_bits
}
pub const fn phase(&self) -> ProgressPhase {
self.phase
}
pub const fn amount(&self) -> ProgressAmount {
self.amount
}
pub(crate) fn initial(bits: usize) -> Self {
Self {
revision: 0,
input_bits: bits,
phase: ProgressPhase::Preprocessing,
amount: ProgressAmount {
completed: 0,
total: ProgressTotal::Unknown,
unit: ProgressUnit::Tasks,
},
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ProgressAmount {
pub(crate) completed: u64,
pub(crate) total: ProgressTotal,
pub(crate) unit: ProgressUnit,
}
impl ProgressAmount {
pub const fn completed(self) -> u64 {
self.completed
}
pub const fn total(self) -> ProgressTotal {
self.total
}
pub const fn unit(self) -> ProgressUnit {
self.unit
}
#[must_use]
pub fn fraction(self) -> Option<f64> {
match self.total {
ProgressTotal::Exact(0) | ProgressTotal::Estimated(0) | ProgressTotal::Unknown => None,
ProgressTotal::Exact(n) | ProgressTotal::Estimated(n) => {
Some(self.completed as f64 / n as f64)
}
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum ProgressTotal {
Exact(u64),
Estimated(u64),
Unknown,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum ProgressUnit {
Candidates,
Primes,
SievePositions,
Relations,
MatrixRows,
MatrixColumns,
MatrixNonzeros,
Iterations,
MatrixProducts,
Tasks,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum ProgressPhase {
Preprocessing,
BuildingFactorBase,
Sieving,
LinearAlgebra,
ExtractingFactor,
Complete,
}
#[derive(Clone, Copy, Debug, Default)]
pub(crate) struct FactorBaseProgress {
pub(crate) bound: u32,
pub(crate) searched_through: u32,
pub(crate) primes_tested: u64,
pub(crate) primes_accepted: u64,
pub(crate) nonresidue_primes: u64,
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct ProgressReportingConfig {
pub(crate) minimum_interval: Duration,
}
impl Default for ProgressReportingConfig {
fn default() -> Self {
Self {
minimum_interval: Duration::from_millis(100),
}
}
}