Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/core/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,14 @@ impl Select for Collection {
}
}

impl IntoIterator for Collection {
type Item = (Idx, Record);
type IntoIter = std::vec::IntoIter<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
self.manifest.into_iter().enumerate().map(|(i, r)| (i as Idx, r)).collect::<Vec<_>>().into_iter()
}
}

#[cfg(test)]
mod test {
use camino::Utf8PathBuf as PathBuf;
Expand All @@ -236,8 +244,8 @@ mod test {

use super::Collection;

use crate::encodings::HashFunctions;
use crate::manifest::Manifest;
use crate::encodings::{ HashFunctions, Idx };
use crate::manifest::{ Manifest, Record };
use crate::prelude::Select;
use crate::selection::Selection;
use crate::signature::Signature;
Expand Down Expand Up @@ -364,6 +372,25 @@ mod test {
assert_eq!(cl.len(), 0);
}

// lock down 'into_iter' implementation :sweat_smile:
#[test]
fn collection_iter() {
// load test sigs
let mut filename = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
// four num=500 sigs
filename.push("../../tests/test-data/genome-s11.fa.gz.sig");
let file = File::open(filename).unwrap();
let reader = BufReader::new(file);
let sigs: Vec<Signature> = serde_json::from_reader(reader).expect("Loading error");
assert_eq!(sigs.len(), 4);
// load sigs into collection + select compatible signatures
let cl = Collection::from_sigs(sigs).unwrap();
// all sigs should remain
assert_eq!(cl.len(), 4);

let _v: Vec<(Idx, Record)> = cl.into_iter().into_iter().collect();
}

#[test]
fn collection_intersect_manifest() {
// load test sigs
Expand Down
4 changes: 4 additions & 0 deletions src/core/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@
self.records.iter()
}

pub fn into_iter(self) -> impl Iterator<Item = Record> {

Check warning on line 246 in src/core/src/manifest.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/manifest.rs#L246

Added line #L246 was not covered by tests
self.records.into_iter()
}

pub fn intersect_manifest(&self, other: &Manifest) -> Self {
// extract tuples from other mf:
let pairs: HashSet<_> = other.iter().collect();
Expand Down
Loading