Skip to content

Commit

Permalink
compiling...
Browse files Browse the repository at this point in the history
  • Loading branch information
ctb committed Nov 3, 2024
1 parent 8f4c008 commit 321ae92
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/core/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ impl Collection {
self.manifest.iter().enumerate().map(|(i, r)| (i as Idx, r))
}

pub fn into_iter(self) -> impl IntoIterator<Item = (Idx, Record)> {
self.manifest.into_iter().enumerate().map(|(i, r)| (i as Idx, r))
}

#[cfg(feature = "parallel")]
pub fn par_iter(&self) -> impl IndexedParallelIterator<Item = (Idx, &Record)> {
self.manifest
Expand Down Expand Up @@ -232,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 @@ -240,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 @@ -368,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

0 comments on commit 321ae92

Please sign in to comment.