shanielh opened a new pull request, #293:
URL: https://github.com/apache/datasketches-rust/pull/293

   Adds `KllSketch::update_with_weight(item, weight)`, equivalent to calling 
`update(item)` `weight` times. This mirrors `update(item, weight)` on the KLL 
sketches in datasketches-java. The name follows 
`CountMinSketch::update_with_weight`.
   
   ## Behavior
   
   - If `weight` is smaller than the free capacity, the item is inserted 
`weight` times as plain updates. No compaction can happen on this path.
   - Otherwise, the update builds an exact sketch of the weighted item and 
merges it in. Since an item at level `h` counts as `2^h`, the exact sketch 
holds one copy of the item at each level whose bit is set in `weight`. Bits 
above the top level fold into `weight >> 60` copies at level 60, because level 
capacities are only defined up to `MAX_NUM_LEVELS` (61). This path costs one 
merge with a sketch of at most 75 items, however large the weight.
   - A weight of zero is a no-op, the same as 
`FrequentItemsSketch::update_with_count`.
   - If the stream weight would exceed `u64::MAX`, it panics without modifying 
the sketch, the same as `update`.
   - `merge`'s body moves into a private `merge_unchecked`, so the weighted 
path can skip checks it has already done without discarding a `Result`. `merge` 
is otherwise unchanged.
   - Serialization is unchanged.
   
   ## Tests
   
   New module `tests-integration/tests/kll_test/update.rs`:
   - zero weight
   - equality with repeated updates in exact mode
   - a single item with a `2^40 + 12345` weight
   - `u64::MAX - 1` weight, with a serialization round trip
   - large weights merged into a full sketch
   - 10,000 weighted items in estimation mode, ranks within the k=200 error 
bound, with a serialization round trip
   - strings
   - overflow leaves the sketch unchanged
   
   `cargo x test`, `cargo clippy --all-features --all-targets --workspace -- -D 
warnings` and `cargo +nightly fmt --all --check` pass locally. I did not run 
taplo, typos or hawkeye locally, so CI will be their first run.
   
   Companion PR for datasketches-cpp: 
https://github.com/apache/datasketches-cpp/pull/542
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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]

Reply via email to