Skip to content

Commit

Permalink
change _merge to consume arg
Browse files Browse the repository at this point in the history
  • Loading branch information
ctb committed Oct 29, 2024
1 parent 7b66529 commit 0e8e4cc
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ impl KmerCountTable {
self._consume(seq.as_str(), skip_bad_kmers)
}

/// private internal function that does the consumption using references.
fn _consume(&mut self, seq: &str, skip_bad_kmers: bool) -> PyResult<u64> {
// Incoming seq len
let new_len = seq.len();
Expand Down Expand Up @@ -675,7 +676,7 @@ impl KmerCountTable {
i += 1;

total_consumed += t.consumed;
self._merge(&t);
self._merge(t);
}
self.consumed = total_consumed;

Expand Down Expand Up @@ -713,23 +714,6 @@ impl KmerCountTable {
.collect()
}

fn _merge(&mut self, other: &KmerCountTable) -> () {
for (hashval, count) in other.counts.iter() {
let this_count = self.counts.entry(*hashval).or_insert(0);
*this_count += count;
}

if self.store_kmers {
let t_hash_to_kmer = other.hash_to_kmer.clone().expect("hash_to_kmer is None!?");

let my_hash_to_kmer = self.hash_to_kmer.as_mut().unwrap();

// here, this will replace, but that's ok.
my_hash_to_kmer.extend(t_hash_to_kmer);
}
()
}

// Python dunder methods for set operations
fn __or__(&self, other: &KmerCountTable) -> HashSet<u64> {
self.union(other)
Expand Down Expand Up @@ -858,6 +842,27 @@ impl KmerCountTable {
}
}


// non-Python accessible methods
impl KmerCountTable {
fn _merge(&mut self, other: KmerCountTable) -> () {
for (hashval, count) in other.counts.iter() {
let this_count = self.counts.entry(*hashval).or_insert(0);
*this_count += count;
}

if self.store_kmers {
let t_hash_to_kmer = other.hash_to_kmer.clone().expect("hash_to_kmer is None!?");

let my_hash_to_kmer = self.hash_to_kmer.as_mut().unwrap();

// here, this will replace, but that's ok.
my_hash_to_kmer.extend(t_hash_to_kmer);
}
()
}
}

#[pyclass]
/// Iterator implementation for KmerCountTable
pub struct KmerCountTableIterator {
Expand Down

0 comments on commit 0e8e4cc

Please sign in to comment.