tisonkun opened a new pull request, #244: URL: https://github.com/apache/datasketches-rust/pull/244
## Summary - replace `ReqValue` with a stored `ReqOrder<T>` policy, leaving `T: Clone` as the only item constraint required by the sketch algorithm - move item serialization behind `ReqItemCodec<T>` parameters on `serialize_with` and `deserialize_with` - preserve the existing primitive API through `DefaultReqOrder`, `DefaultReqItemCodec`, and the default `ReqSketch<T>` type parameter - reject merges between unequal stateful ordering policies This is a follow-up to #243 and keeps REQ generic without making ordering and one particular wire encoding properties of the value type. ## Design rationale REQ needs three distinct capabilities: 1. cloning retained items during compaction 2. a stable total order over accepted items 3. item encoding only when crossing a serialization boundary Those capabilities now have separate bounds. `ReqSketch<T, O = DefaultReqOrder>` stores `O`; codecs are passed only to serialization methods. The default ordering keeps the current numeric float semantics (`-0.0 == +0.0`, NaN rejected), and the default codec keeps the current little-endian primitive images. This follows the strongest existing precedent in this repository: Tuple stores external policy objects, which permits multiple behaviors for one summary type and per-instance configuration. The other generic patterns are less suitable for an open REQ item domain: - `FrequentItemValue` correctly limits its bound to serialization methods, but still combines `Eq + Hash` with one codec implemented on `T`. That forces one encoding per type and prevents downstream crates from adding support for foreign types because of Rust's orphan rules. - `TupleSummaryValue` separates algorithm behavior from serialization, but its codec is still implemented on the summary type and has the same one-encoding/orphan-rule limitation. - sealed `CountMinValue` is appropriate for Count-Min's intentionally closed set of numeric counter types and fixed eight-byte representation, but is not a good model for an open item domain. The split also matches the C++ REQ API, which stores a comparator on `req_sketch<T, Comparator>` and accepts a separate `SerDe` at serialization/deserialization boundaries: [REQ header](https://github.com/apache/datasketches-cpp/blob/c8e42183091558de994b7110c71657e7f880630e/req/include/req_sketch.hpp), [custom type test](https://github.com/apache/datasketches-cpp/blob/c8e42183091558de994b7110c71657e7f880630e/req/test/req_sketch_custom_type_test.cpp). Java remains a fixed-`float` implementation: [ReqSketch.java](https://github.com/apache/datasketches-java/blob/d5cce9b3ad3f7c39faabcebb7f3934c4f73f14fc/src/main/java/org/apache/datasketches/req/ReqSketch.java). ## Public API and compatibility - Existing primitive use remains unchanged: `ReqSketch::<f32>::default()`, `ReqSketch::new`, `serialize`, and `deserialize` still work. - Custom or foreign item types use `with_order` / `new_with_order`; they do not need `PartialOrd` or a codec for in-memory use. - Custom codecs use `serialized_size_bytes_with`, `serialize_with`, and `deserialize_with`. The wire image does not identify either policy, so deserialization explicitly receives both ordering and codec. - `SortedView<T, O>` retains the ordering with its owned snapshot; the default type argument preserves existing `SortedView<T>` annotations. - `merge` requires `O: PartialEq` and treats unequal policy values as incompatible, preventing stateful comparators with different semantics from mixing. - Default policies/codecs are zero-sized and statically dispatched; this adds no dynamic dispatch or allocation to primitive sketches. - `ReqValue` is removed. REQ is still in the unreleased section, so the changelog describes the final API rather than an intermediate migration. ## Tests - custom item without `PartialOrd` or serialization support - custom ordering and codec for a foreign standard-library type - rejection of merges with different stateful orderings - unchanged primitive Rust round trips and C++/Java fixtures - `cargo x check` - `cargo x test` - `cargo x lint` -- 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]
