You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@datasketches.apache.org by "ZENOTME (via GitHub)" <gi...@apache.org> on 2026/04/11 06:44:42 UTC
Re: [PR] fix: add SketchHashable trait to fix inconsistent hashing across types (datasketches-rust)
ZENOTME commented on PR #111:
URL: https://github.com/apache/datasketches-rust/pull/111#issuecomment-4228366307
> I don't get the point clear. Could you provide a failing test to show how the original impl is wrong?
e.g. for u32 in Rust, the following test fails before this PR
```
fn test_unsigned_narrow_integer_inputs_follow_cpp_signed_path() {
let mut u32_sketch = ThetaSketch::builder().build();
u32_sketch.update(u32::MAX);
let mut signed_sketch = ThetaSketch::builder().build();
signed_sketch.update(-1i64);
assert_eq!(u32_sketch.iter().next(), signed_sketch.iter().next());
}
```
but in c++ , follwing is success
```
TEST_CASE("theta sketch: unsigned narrow integer inputs follow cpp
signed path", "[theta_sketch]") {
update_theta_sketch u32_sketch =
update_theta_sketch::builder().build();
u32_sketch.update(uint32_t(UINT32_MAX));
update_theta_sketch signed_sketch =
update_theta_sketch::builder().build();
signed_sketch.update(int64_t(-1));
REQUIRE(u32_sketch.get_num_retained() == 1);
REQUIRE(signed_sketch.get_num_retained() == 1);
REQUIRE(*u32_sketch.begin() == *signed_sketch.begin());
}
```
because in c++, uint32 will be convert to int32_t and then int32_t. So in Rust to make it compatible with this behaviour, we introduce `SketchHashable`.
```
void update(uint32_t value) {
update(static_cast<int32_t>(value));
}
void update(int32_t value) {
update(static_cast<int64_t>(value));
}
void update(int64_t value) {
update(&value, sizeof(value));
}
```
--
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: dev-unsubscribe@datasketches.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org
For additional commands, e-mail: dev-help@datasketches.apache.org