Skip to content

Commit

Permalink
[MRG] Speed-up SeqToHashes() (#1938)
Browse files Browse the repository at this point in the history
* use VecDeque instead of Vec

* cargo fmt
  • Loading branch information
mr-eyes authored Apr 10, 2022
1 parent 93cbd3a commit d1d8397
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/core/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//!
//! A signature is a collection of sketches for a genomic dataset.

use std::collections::VecDeque;
use std::fs::File;
use std::io;
use std::iter::Iterator;
Expand Down Expand Up @@ -169,7 +170,7 @@ pub struct SeqToHashes {
is_protein: bool,
hash_function: HashFunctions,
seed: u64,
hashes_buffer: Vec<u64>,
hashes_buffer: VecDeque<u64>,

dna_configured: bool,
dna_rc: Vec<u8>,
Expand Down Expand Up @@ -214,7 +215,7 @@ impl SeqToHashes {
is_protein,
hash_function,
seed,
hashes_buffer: Vec::with_capacity(1000),
hashes_buffer: VecDeque::with_capacity(1000),
dna_configured: false,
dna_rc: Vec::with_capacity(1000),
dna_ksize: 0,
Expand Down Expand Up @@ -313,7 +314,7 @@ impl Iterator for SeqToHashes {

aa.windows(self.k_size as usize).for_each(|n| {
let hash = crate::_hash_murmur(n, self.seed);
self.hashes_buffer.push(hash);
self.hashes_buffer.push_back(hash);
});

let rc_substr: Vec<u8> = self
Expand All @@ -332,13 +333,13 @@ impl Iterator for SeqToHashes {

aa_rc.windows(self.k_size as usize).for_each(|n| {
let hash = crate::_hash_murmur(n, self.seed);
self.hashes_buffer.push(hash);
self.hashes_buffer.push_back(hash);
});
}
self.kmer_index = self.max_index;
Some(Ok(self.hashes_buffer.remove(0)))
Some(Ok(self.hashes_buffer.remove(0).unwrap()))
} else {
let first_element: u64 = self.hashes_buffer.remove(0);
let first_element: u64 = self.hashes_buffer.pop_front().unwrap();
Some(Ok(first_element))
}
} else {
Expand Down

0 comments on commit d1d8397

Please sign in to comment.