Skip to content

Simpler iteration code. #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2023
Merged
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
20 changes: 13 additions & 7 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn extend_from_slice(
offspring_haplotypes: &mut Vec<u32>,
) -> usize {
let n = get_partition_index(genome, mutations, position);
offspring_haplotypes.extend_from_slice(&genome[..(n as usize)]);
offspring_haplotypes.extend_from_slice(&genome[..n]);
n
}

Expand Down Expand Up @@ -198,14 +198,20 @@ pub fn generate_offspring_genome(
forrustts::genetics::Breakpoint::IndependentAssortment(pos) => *pos,
_ => unimplemented!("unhandled Breakpoint variant"),
};
mut_index += new_mutations[mut_index..]
mut_index += new_mutations
.iter()
.take_while(|k| mutations[**k as usize].position() < bpos)
.inspect(|k| {
let mpos = mutations[**k as usize].position();
update_genome(mutations, mpos, &mut current_genome, offspring_mutations);
offspring_mutations.push(**k);
.skip(mut_index)
.map(|k| {
let mpos = mutations[*k as usize].position();
if mpos < bpos {
update_genome(mutations, mpos, &mut current_genome, offspring_mutations);
offspring_mutations.push(*k);
true
} else {
false
}
})
.take_while(|&k| k)
.count();
update_genome(mutations, bpos, &mut current_genome, offspring_mutations);

Expand Down