diff --git a/src/lib.rs b/src/lib.rs index 9904a84..8e5588d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -846,70 +846,6 @@ impl KmerCountTable { Ok((total_added, new_keys)) } - - /// Subtract counts from another KmerCountTable from this one. - /// - /// # Arguments - /// - /// * `other` - The KmerCountTable to subtract - /// - /// # Returns - /// - /// Returns a PyResult with the number of k-mer counts removed from the table - #[pyo3(signature = (other))] - pub fn subtract(&mut self, other: &KmerCountTable) -> PyResult { - // Check if ksizes match - if self.ksize != other.ksize { - return Err(PyValueError::new_err( - "KmerCountTables must have the same ksize", - )); - } - - // Use atomic counter for thread-safe updates - let total_counts_removed = AtomicU64::new(0); - - // Create a vector to store updates - let updates: Vec<_> = other - .counts - .par_iter() - .filter_map(|(&hash, &count)| { - // Only include hashes that exist in self.counts - self.counts - .get(&hash) - .map(|&self_count| (hash, count, self_count)) - }) - .collect(); - - // Apply updates sequentially - for (hash, other_count, self_count) in updates { - let new_count = if self_count > other_count { - self_count - other_count - } else { - 0 - }; - - let removed = self_count - new_count; - total_counts_removed.fetch_add(removed, Ordering::Relaxed); - - if new_count == 0 { - self.counts.remove(&hash); - } else { - self.counts.insert(hash, new_count); - } - } - - // Update consumed bases - // Ensure consumed doesn't go negative - self.consumed = self.consumed.saturating_sub(other.consumed); - - // Get final count of removed k-mers - let total_removed = total_counts_removed.load(Ordering::Relaxed); - - // Print summary - println!("Removed {} k-mer counts from the table", total_removed); - - Ok(total_removed) - } } #[pyclass]