This is an automated email from the ASF dual-hosted git repository.

tisonkun pushed a commit to branch codex/kll-api-and-performance
in repository https://gitbox.apache.org/repos/asf/datasketches-rust.git

commit a9d61f5591cb0832d538a4c5f6a92b3d1f3e270b
Author: tison <[email protected]>
AuthorDate: Wed Sep 2 12:20:50 2026 +0800

    docs(kll): describe compatibility and query model
---
 CHANGELOG.md                   | 6 +++++-
 datasketches/src/kll/mod.rs    | 5 ++---
 datasketches/src/kll/sketch.rs | 9 ++++++++-
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 339c6a6..c05956d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,7 +6,11 @@ All significant changes to this project will be documented in 
this file.
 
 ### New features
 
-* Add KLL sketches behind the `kll` feature, including rank, quantile, PMF, 
and CDF queries, custom item ordering, merging, and C++/Java-compatible 
serialization.
+* Add KLL sketches behind the `kll` feature, including inclusive and exclusive 
rank, quantile, PMF, and CDF queries; reusable sorted views and batch 
quantiles; comparator-checked merging; custom item ordering and value 
encodings; and C++, Java, and Go-compatible serialization.
+
+### Performance improvements
+
+* Speed up KLL updates and rank queries by caching retained-capacity state and 
scanning retained items directly, and make repeated quantile queries reuse 
sorted levels through an owned `SortedView`.
 
 ## v0.5.0
 
diff --git a/datasketches/src/kll/mod.rs b/datasketches/src/kll/mod.rs
index e65f375..2638dfc 100644
--- a/datasketches/src/kll/mod.rs
+++ b/datasketches/src/kll/mod.rs
@@ -21,9 +21,8 @@
 //! near-optimal accuracy per retained item. It supports one-pass updates,
 //! approximate quantiles, ranks, PMF, and CDF queries.
 //!
-//! This implementation follows Apache DataSketches semantics (Java KllSketch
-//! / KllPreambleUtil, C++ kll_sketch) and uses the same binary serialization
-//! format as those implementations.
+//! This implementation follows Apache DataSketches semantics and uses the 
compact binary
+//! serialization format shared by the Java, C++, and Go implementations.
 //!
 //! # Usage
 //!
diff --git a/datasketches/src/kll/sketch.rs b/datasketches/src/kll/sketch.rs
index bae05f4..175e93a 100644
--- a/datasketches/src/kll/sketch.rs
+++ b/datasketches/src/kll/sketch.rs
@@ -166,6 +166,10 @@ impl<T: Clone, C: KllComparator<T>> KllSketch<T, C> {
     /// Updates the sketch with a new item.
     ///
     /// NaN values are ignored for floating-point types.
+    ///
+    /// # Panics
+    ///
+    /// Panics if the stream weight would exceed [`u64::MAX`].
     pub fn update(&mut self, item: T) {
         if !self.comparator.accepts(&item) {
             return;
@@ -743,7 +747,10 @@ impl<T: Clone, C: KllComparator<T>> KllSketch<T, C> {
         if self.num_retained >= self.capacity {
             self.compress_while_updating();
         }
-        self.n += 1;
+        self.n = self
+            .n
+            .checked_add(1)
+            .expect("stream weight exceeds u64::MAX");
         self.num_retained += 1;
         self.is_level_zero_sorted = false;
         self.levels[0].push(item);


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to