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

tison 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 ae13a83  refactor!: rename get_result to to_sketch (#81)
ae13a83 is described below

commit ae13a8308adfef29c20e56a5afd738fef11b8228
Author: tison <[email protected]>
AuthorDate: Sun Feb 1 13:16:46 2026 +0800

    refactor!: rename get_result to to_sketch (#81)
    
    Signed-off-by: tison <[email protected]>
    Co-authored-by: Copilot <[email protected]>
---
 CHANGELOG.md                         |  4 +++-
 datasketches/src/cpc/union.rs        | 27 ++++++++++++++++++++++++---
 datasketches/src/hll/mod.rs          |  2 +-
 datasketches/src/hll/union.rs        | 12 ++++++------
 datasketches/tests/cpc_union_test.rs | 16 ++++++++--------
 datasketches/tests/hll_union_test.rs | 16 ++++++++--------
 6 files changed, 50 insertions(+), 27 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4319ca0..0ed978a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,12 +7,14 @@ All significant changes to this project will be documented in 
this file.
 ### Breaking changes
 
 * `CountMinSketch` now has a type parameter for the count type. Possible 
values are `u8` to `u64` and `i8` to `i64`.
+* `HllUnion::get_result` is renamed to `HllUnion::to_sketch`.
 
 ### New features
 
 * `CountMinSketch` with unsigned values now supports `halve` and `decay` 
operations.
+* `CpcSketch` and `CpcUnion` are now available for cardinality estimation.
 
-## v0.2.0 (2025-01-14)
+## v0.2.0 (2026-01-14)
 
 This is the initial release. It includes the following sketches:
 
diff --git a/datasketches/src/cpc/union.rs b/datasketches/src/cpc/union.rs
index 1a5255f..7540216 100644
--- a/datasketches/src/cpc/union.rs
+++ b/datasketches/src/cpc/union.rs
@@ -53,7 +53,7 @@
 //! because of the partially inverted Logic in the Sliding flavor, where the 
presence of coupons
 //! is sometimes indicated by the ABSENCE of row_col pairs in the surprises 
table.)
 //!
-//! How does [`CpcUnion::get_result`] work?
+//! How does [`CpcUnion::to_sketch`] work?
 //!
 //! If the union has an Accumulator state, make a copy of that sketch.
 //!
@@ -116,8 +116,29 @@ impl CpcUnion {
         self.lg_k
     }
 
-    /// Returns the result of union operations as a CPC sketch.
-    pub fn get_result(&self) -> CpcSketch {
+    /// Get the union result as a new sketch.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// # use datasketches::cpc::CpcUnion;
+    /// # use datasketches::cpc::CpcSketch;
+    ///
+    /// let mut s1 = CpcSketch::new(12);
+    /// s1.update(&"apple");
+    ///
+    /// let mut s2 = CpcSketch::new(12);
+    /// s2.update(&"apple");
+    /// s2.update(&"banana");
+    ///
+    /// let mut union = CpcUnion::new(12);
+    /// union.update(&s1);
+    /// union.update(&s2);
+    ///
+    /// let result = union.to_sketch();
+    /// assert_eq!(result.estimate().trunc(), 2.0);
+    /// ```
+    pub fn to_sketch(&self) -> CpcSketch {
         match &self.state {
             UnionState::Accumulator(sketch) => {
                 if sketch.is_empty() {
diff --git a/datasketches/src/hll/mod.rs b/datasketches/src/hll/mod.rs
index a587281..f9476fe 100644
--- a/datasketches/src/hll/mod.rs
+++ b/datasketches/src/hll/mod.rs
@@ -99,7 +99,7 @@
 //! union.update(&left);
 //! union.update(&right);
 //!
-//! let result = union.get_result(HllType::Hll8);
+//! let result = union.to_sketch(HllType::Hll8);
 //! assert!(result.estimate() >= 2.0);
 //! ```
 
diff --git a/datasketches/src/hll/union.rs b/datasketches/src/hll/union.rs
index 870c8d8..03fb4ea 100644
--- a/datasketches/src/hll/union.rs
+++ b/datasketches/src/hll/union.rs
@@ -74,7 +74,7 @@ impl HllUnion {
     /// # use datasketches::hll::HllUnion;
     /// let mut union = HllUnion::new(10);
     /// union.update_value("apple");
-    /// let _result = union.get_result(HllType::Hll8);
+    /// let _result = union.to_sketch(HllType::Hll8);
     /// ```
     pub fn new(lg_max_k: u8) -> Self {
         assert!(
@@ -101,7 +101,7 @@ impl HllUnion {
     /// # use datasketches::hll::HllUnion;
     /// let mut union = HllUnion::new(10);
     /// union.update_value("apple");
-    /// let _result = union.get_result(HllType::Hll8);
+    /// let _result = union.to_sketch(HllType::Hll8);
     /// ```
     pub fn update_value<T: Hash>(&mut self, value: T) {
         self.gadget.update(value);
@@ -128,7 +128,7 @@ impl HllUnion {
     /// let mut union = HllUnion::new(10);
     /// union.update(&left);
     /// union.update(&right);
-    /// let result = union.get_result(HllType::Hll8);
+    /// let result = union.to_sketch(HllType::Hll8);
     /// assert!(result.estimate() >= 2.0);
     /// ```
     pub fn update(&mut self, sketch: &HllSketch) {
@@ -237,7 +237,7 @@ impl HllUnion {
         self.gadget = HllSketch::from_mode(final_lg_k, 
Mode::Array8(new_array));
     }
 
-    /// Get the union result as a new sketch
+    /// Get the union result as a new sketch.
     ///
     /// Returns a copy of the internal gadget sketch with the specified target 
HLL type.
     /// If the requested type differs from the gadget's type, conversion is 
performed.
@@ -253,10 +253,10 @@ impl HllUnion {
     /// # use datasketches::hll::HllUnion;
     /// let mut union = HllUnion::new(10);
     /// union.update_value("apple");
-    /// let result = union.get_result(HllType::Hll6);
+    /// let result = union.to_sketch(HllType::Hll6);
     /// assert!(result.estimate() >= 1.0);
     /// ```
-    pub fn get_result(&self, hll_type: HllType) -> HllSketch {
+    pub fn to_sketch(&self, hll_type: HllType) -> HllSketch {
         let gadget_type = self.gadget.target_type();
 
         if hll_type == gadget_type {
diff --git a/datasketches/tests/cpc_union_test.rs 
b/datasketches/tests/cpc_union_test.rs
index 6e8aa32..e8d2017 100644
--- a/datasketches/tests/cpc_union_test.rs
+++ b/datasketches/tests/cpc_union_test.rs
@@ -25,7 +25,7 @@ const RELATIVE_ERROR_FOR_LG_K_11: f64 = 0.02;
 #[test]
 fn test_empty() {
     let union = CpcUnion::new(11);
-    let sketch = union.get_result();
+    let sketch = union.to_sketch();
     assert!(sketch.is_empty());
     assert_eq!(sketch.estimate(), 0.0);
 }
@@ -37,13 +37,13 @@ fn test_two_values() {
     let mut union = CpcUnion::new(11);
     union.update(&sketch);
 
-    let result = union.get_result();
+    let result = union.to_sketch();
     assert!(!result.is_empty());
     assert_eq!(result.estimate(), 1.0);
 
     sketch.update(2);
     union.update(&sketch);
-    let result = union.get_result();
+    let result = union.to_sketch();
     assert!(!result.is_empty());
     assert_that!(
         sketch.estimate(),
@@ -60,7 +60,7 @@ fn test_custom_seed() {
 
     let mut union = CpcUnion::with_seed(11, 123);
     union.update(&sketch);
-    let result = union.get_result();
+    let result = union.to_sketch();
     assert!(!result.is_empty());
     assert_that!(
         result.estimate(),
@@ -94,7 +94,7 @@ fn test_large_values() {
         }
         union.update(&tmp);
     }
-    let result = union.get_result();
+    let result = union.to_sketch();
     assert!(!result.is_empty());
     assert_eq!(result.num_coupons(), union.num_coupons());
     let estimate = sketch.estimate();
@@ -112,7 +112,7 @@ fn test_reduce_k_empty() {
     }
     let mut union = CpcUnion::new(12);
     union.update(&sketch);
-    let result = union.get_result();
+    let result = union.to_sketch();
     assert_eq!(result.lg_k(), 11);
     assert_that!(
         result.estimate(),
@@ -136,7 +136,7 @@ fn test_reduce_k_sparse() {
     }
     union.update(&sketch11);
 
-    let result = union.get_result();
+    let result = union.to_sketch();
     assert_eq!(result.lg_k(), 11);
     assert_that!(
         result.estimate(),
@@ -160,7 +160,7 @@ fn test_reduce_k_window() {
     }
     union.update(&sketch11);
 
-    let result = union.get_result();
+    let result = union.to_sketch();
     assert_eq!(result.lg_k(), 11);
     assert_that!(
         result.estimate(),
diff --git a/datasketches/tests/hll_union_test.rs 
b/datasketches/tests/hll_union_test.rs
index 2f72a70..2f17a29 100644
--- a/datasketches/tests/hll_union_test.rs
+++ b/datasketches/tests/hll_union_test.rs
@@ -169,7 +169,7 @@ fn test_union_mixed_modes() {
     union.update(&sketch1);
     union.update(&sketch2);
 
-    let result = union.get_result(HllType::Hll8);
+    let result = union.to_sketch(HllType::Hll8);
     let estimate = result.estimate();
 
     // Should estimate ~10,003 unique values
@@ -205,9 +205,9 @@ fn test_union_mixed_hll_types() {
     union.update(&sketch3);
 
     // Test getting result in different types
-    let result4 = union.get_result(HllType::Hll4);
-    let result6 = union.get_result(HllType::Hll6);
-    let result8 = union.get_result(HllType::Hll8);
+    let result4 = union.to_sketch(HllType::Hll4);
+    let result6 = union.to_sketch(HllType::Hll6);
+    let result8 = union.to_sketch(HllType::Hll8);
 
     assert_eq!(result4.target_type(), HllType::Hll4);
     assert_eq!(result6.target_type(), HllType::Hll6);
@@ -257,7 +257,7 @@ fn test_union_lg_k_handling() {
     union.update(&sketch3);
     assert_eq!(union.lg_config_k(), 8, "Gadget should downsize to lg_k=8");
 
-    let result = union.get_result(HllType::Hll8);
+    let result = union.to_sketch(HllType::Hll8);
     let estimate = result.estimate();
 
     // Should estimate ~10,000 unique values (0-9,999)
@@ -276,7 +276,7 @@ fn test_union_lg_k_handling() {
     }
 
     union2.update(&sketch_high_precision);
-    let result2 = union2.get_result(HllType::Hll8);
+    let result2 = union2.to_sketch(HllType::Hll8);
     assert_eq!(result2.lg_config_k(), 10, "Result should be at lg_k=10");
 
     let estimate2 = result2.estimate();
@@ -459,7 +459,7 @@ fn test_union_associativity() {
     let mut union1 = HllUnion::new(12);
     union1.update(&sketch_a);
     union1.update(&sketch_b);
-    let ab_sketch = union1.get_result(HllType::Hll8);
+    let ab_sketch = union1.to_sketch(HllType::Hll8);
 
     let mut union2 = HllUnion::new(12);
     union2.update(&ab_sketch);
@@ -470,7 +470,7 @@ fn test_union_associativity() {
     let mut union3 = HllUnion::new(12);
     union3.update(&sketch_b);
     union3.update(&sketch_c);
-    let bc_sketch = union3.get_result(HllType::Hll8);
+    let bc_sketch = union3.to_sketch(HllType::Hll8);
 
     let mut union4 = HllUnion::new(12);
     union4.update(&sketch_a);


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

Reply via email to