This is an automated email from the ASF dual-hosted git repository.
tisonkun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datasketches-rust.git
The following commit(s) were added to refs/heads/main by this push:
new 694513b fix(kll): validate m compatibility before empty check in
KllSketch::merge (#371)
694513b is described below
commit 694513b0c5cbb83356ff922f115602d5406f8b9f
Author: SERAG AHMED <[email protected]>
AuthorDate: Sun Nov 15 12:10:17 2026 +0300
fix(kll): validate m compatibility before empty check in KllSketch::merge
(#371)
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: tison <[email protected]>
---
datasketches/src/kll/sketch.rs | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/datasketches/src/kll/sketch.rs b/datasketches/src/kll/sketch.rs
index dc68d78..b985d0a 100644
--- a/datasketches/src/kll/sketch.rs
+++ b/datasketches/src/kll/sketch.rs
@@ -182,18 +182,19 @@ impl<T: Clone + Ord> KllSketch<T> {
///
/// # Errors
///
- /// Returns an error if the combined stream weight exceeds [`u64::MAX`].
+ /// Returns an error without modifying the sketch if the combined stream
weight exceeds
+ /// [`u64::MAX`].
pub fn merge(&mut self, other: &KllSketch<T>) -> Result<(), Error> {
- if other.is_empty() {
- return Ok(());
- }
-
if self.m != other.m {
return Err(Error::invalid_argument(format!(
- "cannot merge sketches with different m values: {} and {}",
+ "cannot merge KLL sketches with different m values: expected
{}, got {}",
self.m, other.m
)));
}
+
+ if other.is_empty() {
+ return Ok(());
+ }
let final_n = self.n.checked_add(other.n).ok_or_else(|| {
Error::invalid_argument(format!(
"combined stream weight exceeds {}: left {}, right {}",
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]