Rename Layer to KmerLayer across obikindex and obikphylo

This commit renames the `Layer` type to `KmerLayer` throughout the `obikindex` and `obikphylo` crates. All imports, struct fields, function signatures, pattern matches, and instantiation calls have been updated accordingly. The change is a purely structural refactor that tightens type constraints without altering runtime behavior or data models.
This commit is contained in:
Eric Coissac
2026-08-21 10:27:29 +02:00
parent 4b7b3c3c1a
commit 31bb324752
7 changed files with 134 additions and 90 deletions
+7 -6
View File
@@ -1,6 +1,6 @@
use rayon::prelude::*;
use obikindex::layer::Layer;
use obikindex::layer::KmerLayer;
use obikseq::CanonicalKmer;
use obisys::progress_bar;
@@ -31,7 +31,7 @@ use obikindex::{KmerIndex, OKIResult};
/// `DevDocMD/implementation/partition_layer_cache.md`). Its
/// sibling-specific extension (`iter_minorants_batch`) lives in `iter.rs`.
pub(super) struct PartitionCache {
mats: Vec<Vec<Layer>>,
mats: Vec<Vec<KmerLayer>>,
/// Whether every `FamilyMask` field in this index's sibling annexes can
/// be trusted as a real layer index (`n_layers <= 7`, the same decision
/// `build_layer_sibling_annex` makes when writing them) — computed once
@@ -47,9 +47,9 @@ pub(super) struct PartitionCache {
impl PartitionCache {
pub(super) fn build(index: &KmerIndex, n_parts: usize, with_counts: bool) -> OKIResult<Self> {
let pb = progress_bar("open_partitions", n_parts as u64, "partitions");
let built: Vec<(Vec<Layer>, usize)> = (0..n_parts)
let built: Vec<(Vec<KmerLayer>, usize)> = (0..n_parts)
.into_par_iter()
.map(|part| -> OKIResult<(Vec<Layer>, usize)> {
.map(|part| -> OKIResult<(Vec<KmerLayer>, usize)> {
let index_dir = index.index_dir(part);
if !index_dir.exists() {
pb.inc(1);
@@ -58,7 +58,8 @@ impl PartitionCache {
let meta = index.partition_meta(part)?;
let mut mats = Vec::with_capacity(meta.n_layers);
for l in 0..meta.n_layers {
let Ok(mat) = Layer::open(&index.layer_dir(part, l), &meta.mode, with_counts)
let Ok(mat) =
KmerLayer::open(&index.layer_dir(part, l), &meta.mode, with_counts)
else {
continue;
};
@@ -215,7 +216,7 @@ impl PartitionCache {
/// `hits` gets its slots (evidence-probed vs. trusted `index_batch`) — this
/// is everything after that.
fn resolve_layer_hits(
mat: &Layer,
mat: &KmerLayer,
hits: &[(usize, usize, u8)],
n_genomes: usize,
on_hit: &mut impl FnMut(usize, u8, usize),
+3 -3
View File
@@ -60,7 +60,7 @@ use obipipeline::{ThrottleGuard, throttle};
use obikindex::KmerIndex;
use obikindex::{OKIError, OKIResult};
use obikindex::layer::Layer;
use obikindex::layer::KmerLayer;
use super::cache::PartitionCache;
use super::helpers::central_base;
@@ -134,7 +134,7 @@ pub(crate) fn sibling_layer_dirs(index: &KmerIndex) -> OKIResult<Vec<PathBuf>> {
/// `mat` (a `TypedLayer<D>`) already bundles the MPHF, and each `SiblingEntry`
/// arrives with its kmer and mask already in hand from `iter_minorants_batch`.
struct LayerCtx {
mat: Layer,
mat: KmerLayer,
n_parts: usize,
n_genomes: usize,
n_cols: usize,
@@ -197,7 +197,7 @@ pub(super) fn scan_layer_families(
let meta = PartitionMeta::load(index_dir).map_err(olm_to_ok)?;
let annex = Arc::new(SiblingAnnex::open(&layer_dir.join(ANNEX_FILE_NAME))?);
let mat = Layer::open(layer_dir, &meta.mode, with_counts).map_err(olm_to_ok)?;
let mat = KmerLayer::open(layer_dir, &meta.mode, with_counts).map_err(olm_to_ok)?;
let n_cols = mat.n_cols().min(n_genomes);
let ctx = Arc::new(LayerCtx {
+53 -21
View File
@@ -28,8 +28,8 @@
use std::sync::Arc;
use obikindex::layer::{KmerIter, LayerData, TypedLayer};
use obikseq::CanonicalKmer;
use obikindex::layer::{KmerIter, TypedLayer, LayerData};
use super::{FamilyMask, SiblingAnnex};
@@ -151,24 +151,44 @@ pub trait SiblingLayerExt {
/// Like [`iter_minorants`](Self::iter_minorants), yielding `batch_size`
/// minorants at a time.
fn iter_minorants_batch(&self, annex: Arc<SiblingAnnex>, batch_size: usize) -> MinorantBatchIter;
fn iter_minorants_batch(
&self,
annex: Arc<SiblingAnnex>,
batch_size: usize,
) -> MinorantBatchIter;
}
impl<D: LayerData> SiblingLayerExt for TypedLayer<D> {
fn iter_siblings(&self, annex: Arc<SiblingAnnex>) -> SiblingIter {
SiblingIter { kmers: self.iter_kmers(), annex, order: 0 }
SiblingIter {
kmers: self.iter_kmers(),
annex,
order: 0,
}
}
fn iter_siblings_batch(&self, annex: Arc<SiblingAnnex>, batch_size: usize) -> SiblingBatchIter {
SiblingBatchIter { inner: self.iter_siblings(annex), batch_size }
SiblingBatchIter {
inner: self.iter_siblings(annex),
batch_size,
}
}
fn iter_minorants(&self, annex: Arc<SiblingAnnex>) -> MinorantIter {
MinorantIter { inner: self.iter_siblings(annex) }
MinorantIter {
inner: self.iter_siblings(annex),
}
}
fn iter_minorants_batch(&self, annex: Arc<SiblingAnnex>, batch_size: usize) -> MinorantBatchIter {
MinorantBatchIter { inner: self.iter_minorants(annex), batch_size }
fn iter_minorants_batch(
&self,
annex: Arc<SiblingAnnex>,
batch_size: usize,
) -> MinorantBatchIter {
MinorantBatchIter {
inner: self.iter_minorants(annex),
batch_size,
}
}
}
@@ -178,36 +198,48 @@ impl<D: LayerData> SiblingLayerExt for TypedLayer<D> {
/// depend on which `D` is inside), so no boxing is needed. `obikindex::layer`
/// itself can't implement this: "family"/"minorant" are phylo concepts, it
/// stays kmer/slot-mapping only (see the module docs above).
impl SiblingLayerExt for obikindex::layer::Layer {
impl SiblingLayerExt for obikindex::layer::KmerLayer {
fn iter_siblings(&self, annex: Arc<SiblingAnnex>) -> SiblingIter {
match self {
obikindex::layer::Layer::Count(l) => l.iter_siblings(annex),
obikindex::layer::Layer::Presence(l) => l.iter_siblings(annex),
obikindex::layer::Layer::Empty { .. } => panic!("iter_siblings() called on an Empty layer"),
obikindex::layer::KmerLayer::Count(l) => l.iter_siblings(annex),
obikindex::layer::KmerLayer::Presence(l) => l.iter_siblings(annex),
obikindex::layer::KmerLayer::Empty { .. } => {
panic!("iter_siblings() called on an Empty layer")
}
}
}
fn iter_siblings_batch(&self, annex: Arc<SiblingAnnex>, batch_size: usize) -> SiblingBatchIter {
match self {
obikindex::layer::Layer::Count(l) => l.iter_siblings_batch(annex, batch_size),
obikindex::layer::Layer::Presence(l) => l.iter_siblings_batch(annex, batch_size),
obikindex::layer::Layer::Empty { .. } => panic!("iter_siblings_batch() called on an Empty layer"),
obikindex::layer::KmerLayer::Count(l) => l.iter_siblings_batch(annex, batch_size),
obikindex::layer::KmerLayer::Presence(l) => l.iter_siblings_batch(annex, batch_size),
obikindex::layer::KmerLayer::Empty { .. } => {
panic!("iter_siblings_batch() called on an Empty layer")
}
}
}
fn iter_minorants(&self, annex: Arc<SiblingAnnex>) -> MinorantIter {
match self {
obikindex::layer::Layer::Count(l) => l.iter_minorants(annex),
obikindex::layer::Layer::Presence(l) => l.iter_minorants(annex),
obikindex::layer::Layer::Empty { .. } => panic!("iter_minorants() called on an Empty layer"),
obikindex::layer::KmerLayer::Count(l) => l.iter_minorants(annex),
obikindex::layer::KmerLayer::Presence(l) => l.iter_minorants(annex),
obikindex::layer::KmerLayer::Empty { .. } => {
panic!("iter_minorants() called on an Empty layer")
}
}
}
fn iter_minorants_batch(&self, annex: Arc<SiblingAnnex>, batch_size: usize) -> MinorantBatchIter {
fn iter_minorants_batch(
&self,
annex: Arc<SiblingAnnex>,
batch_size: usize,
) -> MinorantBatchIter {
match self {
obikindex::layer::Layer::Count(l) => l.iter_minorants_batch(annex, batch_size),
obikindex::layer::Layer::Presence(l) => l.iter_minorants_batch(annex, batch_size),
obikindex::layer::Layer::Empty { .. } => panic!("iter_minorants_batch() called on an Empty layer"),
obikindex::layer::KmerLayer::Count(l) => l.iter_minorants_batch(annex, batch_size),
obikindex::layer::KmerLayer::Presence(l) => l.iter_minorants_batch(annex, batch_size),
obikindex::layer::KmerLayer::Empty { .. } => {
panic!("iter_minorants_batch() called on an Empty layer")
}
}
}
}