Introduce obikalgorithm crate to unify pipeline algorithms
Define a shared Algorithm trait with an associated Output type and a parameterless run(&mut self) method. Refactor PartitionRouter, Dereplicator, Counter, and LayerBuilder to implement the trait, standardizing receivers to &mut self and moving configuration and progress callbacks to dedicated builder setters. Decouple error handling using a generic boxed error type and update workspace dependencies accordingly.
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
[package]
|
||||
name = "obikalgorithm"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
@@ -0,0 +1,36 @@
|
||||
//! Shared trait unifying the four indexing-pipeline algorithms in
|
||||
//! `obikindexer::algorithms` (`PartitionRouter`/`Dereplicator`/`Counter`/
|
||||
//! `LayerBuilder`) — see `DevDocMD/implementation/partition_layer_cache.md`.
|
||||
|
||||
/// Boxed, generic error for `Algorithm::run` — this crate defines the
|
||||
/// *shape* algorithms conform to, not any specific failure domain, so it
|
||||
/// must not depend on (and re-expose) any one algorithm's own I/O-flavored
|
||||
/// error enum (e.g. `obiskio::SKError`). Any concrete error type
|
||||
/// (`SKError`, `std::io::Error`, ...) converts into this automatically via
|
||||
/// `?`, through `std`'s own blanket `From<E: Error + Send + Sync> for
|
||||
/// Box<dyn Error + Send + Sync>` — no dependency on the crate that defines
|
||||
/// `E` needed here.
|
||||
pub type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
/// Common shape across the four pipeline algorithms: two-phase
|
||||
/// construction (`new` + setters — not part of this trait, since `new`'s
|
||||
/// argument and the setters differ per algorithm), then `run`.
|
||||
///
|
||||
/// `run` takes `&mut self`, not `&self`: forced by `PartitionRouter`,
|
||||
/// which holds real per-run state (open file writers) — the other three
|
||||
/// don't need mutability but accept the same receiver rather than the
|
||||
/// trait special-casing one implementor.
|
||||
///
|
||||
/// Progress reporting is deliberately *not* part of this signature: the
|
||||
/// four algorithms report progress under genuinely different concurrency
|
||||
/// models (sequential, parallel-rayon, single-controller-thread), so each
|
||||
/// keeps its own `.on_progress(...)` setter with its own callback bound
|
||||
/// instead of a shared one here — forcing a single shape would mean
|
||||
/// wrapping the parallel algorithms' callback in a `Mutex` for no
|
||||
/// benefit.
|
||||
pub trait Algorithm {
|
||||
type Output;
|
||||
fn run(&mut self) -> Result<Self::Output>;
|
||||
}
|
||||
Reference in New Issue
Block a user