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 5ff0dea refactor(cpc,req): remove public serialization-size helpers
(#346)
5ff0dea is described below
commit 5ff0dea7f02daf9f557fba7713bfd68825751f14
Author: tison <[email protected]>
AuthorDate: Thu Nov 12 01:15:07 2026 +0800
refactor(cpc,req): remove public serialization-size helpers (#346)
---
CHANGELOG.md | 1 +
datasketches/src/cpc/sketch.rs | 55 ------------------------------
datasketches/src/req/sketch.rs | 2 +-
tests-integration/tests/cpc_test/update.rs | 10 ------
4 files changed, 2 insertions(+), 66 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a4c114f..73afc88 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@ All significant changes to this project will be documented in
this file.
### Breaking changes
* `CountMinSketch::new` and `CountMinSketch::with_seed` now create serial
version 2 sketches, require `num_hashes` in `1..=127`, and emit images that
require a version 2 reader. Version 2 enables cross-language interchange when
using `i64` counters and the documented input encodings, while existing version
1 images remain readable, updatable, and serializable as version 1.
`CountMinSketch::merge` rejects mixing version 1 and version 2 sketches;
upgrade readers before writers and rebuild [...]
+* `CpcSketch::max_serialized_bytes` and `ReqSketch::serialized_size_bytes` are
removed; serialize the sketch and inspect `len()` on the returned byte buffer
when the encoded size is needed.
### New features
diff --git a/datasketches/src/cpc/sketch.rs b/datasketches/src/cpc/sketch.rs
index 9e0eee5..a2ca362 100644
--- a/datasketches/src/cpc/sketch.rs
+++ b/datasketches/src/cpc/sketch.rs
@@ -897,58 +897,3 @@ impl CpcSketch {
bytes.write_f64_le(self.hip_est_accum);
}
}
-
-impl CpcSketch {
- /// Returns the estimated maximum compressed serialized size of a sketch.
- ///
- /// The actual size of a compressed CPC sketch has a small random
variance, but the following
- /// empirically measured size should be large enough for at least 99.9
percent of sketches.
- ///
- /// For small values of `n` the size can be much smaller.
- ///
- /// # Errors
- ///
- /// Returns an error if `lg_k` is not in the range `[4, 26]`.
- pub fn max_serialized_bytes(lg_k: u8) -> Result<usize, Error> {
- if !(MIN_LG_K..=MAX_LG_K).contains(&lg_k) {
- return Err(Error::invalid_argument(format!(
- "lg_k must be in [{MIN_LG_K}, {MAX_LG_K}], got {lg_k}"
- )));
- }
-
- // These empirical values for the 99.9th percentile of size in bytes
were measured using
- // 100,000 trials. The value for each trial is the maximum of 5*16=80
measurements
- // that were equally spaced over values of the quantity C/K between
3.0 and 8.0.
- // This table does not include the worst-case space for the preamble,
which is added
- // by the function.
- const MAX_PREAMBLE_SIZE_BYTES: usize = 40;
- const EMPIRICAL_SIZE_MAX_LGK: u8 = 19;
- const EMPIRICAL_MAX_SIZE_FACTOR: f64 = 0.6; // 0.6 = 4.8 / 8.0
- static EMPIRICAL_MAX_SIZE_BYTES: [usize; 16] = [
- 24, // lg_k = 4
- 36, // lg_k = 5
- 56, // lg_k = 6
- 100, // lg_k = 7
- 180, // lg_k = 8
- 344, // lg_k = 9
- 660, // lg_k = 10
- 1292, // lg_k = 11
- 2540, // lg_k = 12
- 5020, // lg_k = 13
- 9968, // lg_k = 14
- 19836, // lg_k = 15
- 39532, // lg_k = 16
- 78880, // lg_k = 17
- 157516, // lg_k = 18
- 314656, // lg_k = 19
- ];
-
- let max_bytes = if lg_k <= EMPIRICAL_SIZE_MAX_LGK {
- EMPIRICAL_MAX_SIZE_BYTES[(lg_k - MIN_LG_K) as usize] +
MAX_PREAMBLE_SIZE_BYTES
- } else {
- let k = 1 << lg_k;
- ((EMPIRICAL_MAX_SIZE_FACTOR * k as f64) as usize) +
MAX_PREAMBLE_SIZE_BYTES
- };
- Ok(max_bytes)
- }
-}
diff --git a/datasketches/src/req/sketch.rs b/datasketches/src/req/sketch.rs
index fb0245e..3740ca6 100644
--- a/datasketches/src/req/sketch.rs
+++ b/datasketches/src/req/sketch.rs
@@ -504,7 +504,7 @@ where
}
/// Returns the number of bytes required to serialize the sketch.
- pub fn serialized_size_bytes(&self) -> usize
+ fn serialized_size_bytes(&self) -> usize
where
T: ReqValue,
{
diff --git a/tests-integration/tests/cpc_test/update.rs
b/tests-integration/tests/cpc_test/update.rs
index 99a1cb5..053adb0 100644
--- a/tests-integration/tests/cpc_test/update.rs
+++ b/tests-integration/tests/cpc_test/update.rs
@@ -17,7 +17,6 @@
use datasketches::common::NumStdDev;
use datasketches::cpc::CpcSketch;
-use datasketches::error::ErrorKind;
use googletest::assert_that;
use googletest::prelude::ge;
use googletest::prelude::le;
@@ -58,12 +57,3 @@ fn test_many_values() {
assert_that!(sketch.estimate(), ge(sketch.lower_bound(NumStdDev::One)));
assert_that!(sketch.estimate(), le(sketch.upper_bound(NumStdDev::One)));
}
-
-#[test]
-fn test_max_serialized_bytes_validates_lg_k() {
- assert!(CpcSketch::max_serialized_bytes(11).unwrap() > 0);
- for lg_k in [3, 27] {
- let error = CpcSketch::max_serialized_bytes(lg_k).unwrap_err();
- assert_eq!(error.kind(), ErrorKind::InvalidArgument);
- }
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]