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

   > **Disclaimer:** This contribution was written entirely by an AI coding
   > assistant (Claude Opus 4.8) and has only been manually reviewed.
   
   ## Motivation
   
   `FrequentItemsSketch::update` and `update_with_count` take the item by value
   (`T`). When `T` is an owned, heap-allocated type such as `String`, a caller 
that
   streams many repeated items must allocate an owned key for *every* 
observation —
   including when the item is already tracked, in which case
   `adjust_or_put_value` only compares the key by reference and then immediately
   drops the freshly allocated value. For a stream dominated by a small set of
   recurring items (a common case for a frequent-items sketch), that is one 
wasted
   allocation per occurrence.
   
   ## Change
   
   Add borrowed-key update methods that allocate an owned key only when the 
item is
   actually inserted:
   
   - `FrequentItemsSketch::update_borrowed<Q>(&Q)`
   - `FrequentItemsSketch::update_with_count_borrowed<Q>(&Q, u64)`
   - `ReversePurgeItemHashMap::adjust_or_put_value_borrowed<Q>(&Q, u64)` (backs 
the
     two above)
   
   They mirror the existing `update` / `update_with_count` pair and are bounded 
by
   `T: Borrow<Q>, Q: Eq + Hash + ToOwned<Owned = T> + ?Sized`, so for example a
   `FrequentItemsSketch<String>` can be updated directly from a `&str`. The hit
   path increments the counter with no allocation; the insert path calls
   `key.to_owned()` exactly as the owned path does today. `hash_item` is 
relaxed to
   `T: Hash + ?Sized` so unsized borrowed keys such as `str` can be hashed
   directly.
   
   ## Testing
   
   - Added doctests for both new sketch methods.
   - `cargo test -p datasketches --features frequencies --lib` and `--doc` pass
     (including the new doctests).
   


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