tisonkun commented on code in PR #118:
URL: https://github.com/apache/datasketches-rust/pull/118#discussion_r3215013926
##########
datasketches/src/cpc/sketch.rs:
##########
@@ -172,7 +171,25 @@ impl CpcSketch {
/// Update the sketch with a hashable value.
///
- /// For `f32`/`f64` values, use `update_f32`/`update_f64` instead.
+ /// You may use [`hash_value`](crate::hash_value) wrappers when matching
other datasketches
+ /// implementations require a specific value hashing strategy.
+ ///
+ /// # Examples
+ ///
+ /// ```rust
+ /// use datasketches::cpc::CpcSketch;
+ /// use datasketches::hash_value;
+ ///
+ /// let mut sketch = CpcSketch::with_seed(11, 123);
+ /// sketch.update(1);
+ /// sketch.update(2);
+ /// sketch.update(3);
+ ///
+ /// let mut sketch = CpcSketch::with_seed(11, 123);
+ /// sketch.update(hash_value::canonical_float::from_f64(1.5));
+ /// sketch.update(hash_value::canonical_float::from_f64(2.5));
+ /// sketch.update(hash_value::canonical_float::from_f64(3.5));
+ /// ```
pub fn update<T: Hash>(&mut self, value: T) {
Review Comment:
One possible future approach to prevent users from accidentally using the
Rust standard library's Hash trait without realizing it, is to implement our
own `HashValue` or `Hashable` trait.
We could then provide a simple wrapper for Rust's std Hash like our current
hash_value wrappers. In this scenario, users would be required to either use
our wrapper when passing data to `update`, or implement the `Hashable` logic
themselves.
I think this could serve as a potential future extension. However, forcing
users to use a specific wrapper or an additional `Hashable` trait might feel
unnatural at the interface level, especially since we would never have a
blanket `impl<T: Hash> Hashable for T`.
I will leave this here as a record. If we find a need for this in the
future, we can revisit and implement this idea.
FYI @ZENOTME @notfilippo
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]