Start of a huge refactoring
This commit is contained in:
@@ -240,6 +240,26 @@ impl KmerLayer {
|
||||
}
|
||||
}
|
||||
|
||||
// content_layer.rs, à côté de fill_sub_matrix_carries
|
||||
/// Batch, genome-major column extraction — `out[g][i]` = genome `g`'s raw
|
||||
/// value at `slots[i]` (count as-is, presence promoted to 0/1). Column-first,
|
||||
/// like the underlying storage: one read pass per genome column, not one per
|
||||
/// kmer.
|
||||
pub fn fill_sub_matrix(&self, slots: &[usize], out: &mut [Vec<u32>]) {
|
||||
match self {
|
||||
KmerLayer::Count { layer, .. } => layer.fill_sub_matrix(slots, out),
|
||||
KmerLayer::Presence { layer, .. } => {
|
||||
let mut bools: Vec<Vec<bool>> = out.iter().map(|_| Vec::new()).collect();
|
||||
layer.fill_sub_matrix(slots, &mut bools);
|
||||
for (o, b) in out.iter_mut().zip(bools.iter()) {
|
||||
o.clear();
|
||||
o.extend(b.iter().map(|&v| v as u32));
|
||||
}
|
||||
}
|
||||
KmerLayer::Empty { .. } => panic!("Layer::fill_sub_matrix() called on an Empty layer"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Raw MPHF lookup: kmer → slot, no membership check.
|
||||
pub fn hash(&self, kmer: CanonicalKmer) -> usize {
|
||||
match self {
|
||||
|
||||
@@ -412,6 +412,12 @@ impl MphfOnly {
|
||||
pub fn index(&self, kmer: CanonicalKmer) -> usize {
|
||||
self.0.index(&kmer.raw())
|
||||
}
|
||||
|
||||
/// Batch form of [`index`](Self::index) — one MPHF lookup pass over the
|
||||
/// whole slice instead of one call per kmer.
|
||||
pub fn index_batch(&self, kmers: &[CanonicalKmer]) -> Vec<usize> {
|
||||
kmers.iter().map(|&k| self.index(k)).collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl MphfLayer {
|
||||
|
||||
@@ -61,7 +61,7 @@ pub struct KmerPartition {
|
||||
impl KmerPartition {
|
||||
pub fn new(index: &KmerIndex, i: usize) -> Self {
|
||||
KmerPartition {
|
||||
partition_dir: index.dir().join(format!("part_{i:05}")),
|
||||
partition_dir: index_dir(index.dir(), i),
|
||||
id: i,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user