From 0e8e4cc5b7a17a6ced163fd1586afd4fe751290d Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Tue, 29 Oct 2024 11:40:56 -0700 Subject: [PATCH] change _merge to consume arg --- src/lib.rs | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 90331d1..661a1a4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { // Incoming seq len let new_len = seq.len(); @@ -675,7 +676,7 @@ impl KmerCountTable { i += 1; total_consumed += t.consumed; - self._merge(&t); + self._merge(t); } self.consumed = total_consumed; @@ -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 { self.union(other) @@ -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 {