refactor: unify iterator construction in nonzero_iter

Change the return type of `nonzero_iter` from an opaque `impl Iterator` to a `Box<dyn Iterator>`. This enables direct return coercion in the `Count` layer branch, removing an explicit `Box::new()` wrapper and aligning it with the existing `Presence` implementation. The modification shifts iterator construction to runtime dynamic dispatch while preserving the public API contract and iteration semantics.
This commit is contained in:
Eric Coissac
2026-08-28 19:08:55 +02:00
parent b0890d1781
commit 10a0909687
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -224,7 +224,7 @@ impl KmerLayer {
pub fn nonzero_iter<'a>(&'a self, slots: &'a [usize]) -> Box<dyn Iterator<Item = (usize, usize, u32)> + 'a> { pub fn nonzero_iter<'a>(&'a self, slots: &'a [usize]) -> Box<dyn Iterator<Item = (usize, usize, u32)> + 'a> {
match self { match self {
KmerLayer::Presence { layer, .. } => layer.nonzero_iter(slots), KmerLayer::Presence { layer, .. } => layer.nonzero_iter(slots),
KmerLayer::Count { layer, .. } => Box::new(layer.nonzero_iter(slots)), KmerLayer::Count { layer, .. } => layer.nonzero_iter(slots),
KmerLayer::Empty { .. } => panic!("Layer::nonzero_iter() called on an Empty layer"), KmerLayer::Empty { .. } => panic!("Layer::nonzero_iter() called on an Empty layer"),
} }
} }
+1 -1
View File
@@ -418,7 +418,7 @@ impl TypedLayer<PersistentCompactIntMatrix> {
/// Every nonzero `(idx into slots, col, value)` triple among `slots` — /// Every nonzero `(idx into slots, col, value)` triple among `slots` —
/// delegates to `PersistentCompactIntMatrix::nonzero_iter`. /// delegates to `PersistentCompactIntMatrix::nonzero_iter`.
pub fn nonzero_iter<'a>(&'a self, slots: &'a [usize]) -> impl Iterator<Item = (usize, usize, u32)> + 'a { pub fn nonzero_iter<'a>(&'a self, slots: &'a [usize]) -> Box<dyn Iterator<Item = (usize, usize, u32)> + 'a> {
self.data.nonzero_iter(slots) self.data.nonzero_iter(slots)
} }
} }