tisonkun opened a new issue, #364:
URL: https://github.com/apache/datasketches-rust/issues/364
## Summary
Constructor entry points and `Default` implementations across `datasketches`
are currently split unevenly across sketch families. Some builders implement
`Default` with no `new()`, some implement `new(policy)` with no `Default`, and
some parameterized types implement `Default` while comparable siblings omit it.
## Current State
| Type |
`Default` | Direct Constructor | Builder / Notes
|
| ------------------------------------------------------------------- |
--------- | ---------------------------------------------- |
--------------------------------------------------------------------------- |
| `CpcSketch`, `CpcUnion` | Yes
| `new(lg_k)`, `with_seed(lg_k, seed)` | Uses `DEFAULT_LG_K =
11` in `datasketches/src/cpc/mod.rs` |
| `HllType` | No
| Enum variants `Hll4`, `Hll6`, `Hll8` | Contrast `RankAccuracy`
(`#[default] HighRank`) |
| `HllSketch` | No
| `new(lg_config_k, hll_type)` |
`datasketches/src/hll/mod.rs` defines no `DEFAULT_LG_K` |
| `HllUnion` | No
| `new(lg_max_k)` | Internally creates an
`HllType::Hll8` gadget |
| `KllSketch<T>` | Yes
| `new(k)` | Uses `DEFAULT_K = 200`
|
| `ReqSketch<T>` | Yes
| `new(k, rank_accuracy)` | Uses `DEFAULT_K = 12`
and `RankAccuracy::HighRank` |
| `TDigestMut` | Yes
| `new(k)` | Uses `DEFAULT_K = 200`
|
| `ThetaSketchBuilder`, `ThetaUnionBuilder` | Yes
| None | Configured via chained
setters and `.build()` |
| `ThetaIntersection`, `ThetaANotB`, `ThetaJaccardSimilarity` | Yes
| `with_seed(seed)` only | Contrast
`TupleIntersection::new` + `with_seed` |
| `TupleANotB`, `TupleJaccardSimilarity` | Yes
| `with_seed(seed)` only | Symmetric with Theta
operators |
| `TupleSketchBuilder<P>`, `TupleUnionBuilder<P>` | No
| `new(policy: P)` |
`DefaultUpdatePolicy<S>` / `DefaultUnionPolicy<S>` already derive `Default` |
| `TupleIntersection<P>` | No
| `new(policy: P)`, `with_seed(policy, seed)` | Omits `Default` even
when `P: Default + SummaryCombinePolicy` |
| `CountMinSketch<T>`, `FrequentItemsSketch<T>` | No
| `new(...)` (+ `with_seed` on CountMin) | Sizing parameters are
domain-specific; intentionally omit `Default` |
| `BloomFilterBuilder`, `XorFilterBuilder` | No
| `with_accuracy`/`with_size`, `new`/`with_seed` | Require sizing
parameters or `XorFilterType`; omit `Default` |
| `TDigest`, `CompactThetaSketch`, `CompactTupleSketch`, `CpcWrapper` | No
| `deserialize` / `freeze` / `compact` | Immutable
query/snapshot types; intentionally omit `Default` |
## Proposed Changes
1. Implement `Default` for `HllType` (evaluating `#[default] Hll8`, matching
`HllUnion`'s internal gadget choice and docs noting `Hll8` is generally the
fastest representation to update) and add `DEFAULT_LG_K` plus `Default` for
`HllSketch` (and `HllUnion` for symmetry with `CpcSketch`/`CpcUnion`, choosing
between `DEFAULT_LG_K = 12` as in `datasketches/src/thetafamily/` or
`DEFAULT_LG_K = 11` as in `datasketches/src/cpc/mod.rs`).
2. Implement `Default` for `TupleSketchBuilder<P>`, `TupleUnionBuilder<P>`,
and `TupleIntersection<P>` bounded on `P: Default` alongside their existing
policy traits (`SummaryPolicy` / `SummaryCombinePolicy`), calling
`Self::new(P::default())` so `DefaultUpdatePolicy<S>` and
`DefaultUnionPolicy<S>` users get the same ergonomics as Theta builders and
operators.
3. Evaluate aligning `ThetaSketchBuilder` / `ThetaUnionBuilder` and `Theta*`
/ `Tuple*` operator constructors (such as whether `ThetaSketchBuilder` /
`ThetaUnionBuilder` should keep `Default`-only or also expose `new()`, and
whether `ThetaIntersection` / `*ANotB` / `*JaccardSimilarity` keep `Default` +
`with_seed` without breaking existing callers).
4. Document the crate's constructor vs `*Builder` and `Default` policy in
`CONTRIBUTING.md`:
- Direct `new(...)` / `with_seed(..., seed)` is preferred when
construction takes one or two core parameters without a multi-field optional
configuration matrix (`KllSketch`, `ReqSketch`, `TDigestMut`, `CpcSketch`,
`HllSketch`, `CountMinSketch`, `FrequentItemsSketch`).
- A `*Builder` is preferred when construction combines multiple optional
defaults (`ThetaSketchBuilder`, `TupleSketchBuilder`, `ThetaUnionBuilder`,
`TupleUnionBuilder`), distinct sizing modes
(`BloomFilterBuilder::with_accuracy` / `with_size`), or multi-step input
buffering prior to finalization (`XorFilterBuilder`).
- `Default` should be implemented whenever an unambiguous, standard empty
configuration exists (including generic types when `P: Default`), and
intentionally omitted for domain-sized filters/sketches and immutable
frozen/compact views.
## Acceptance Criteria
- `HllType`, `HllSketch`, `HllUnion`, `TupleSketchBuilder<P>`,
`TupleUnionBuilder<P>`, and `TupleIntersection<P>` implement `Default` where
appropriate, with unit or integration tests exercising default-constructed
instances.
- `CONTRIBUTING.md` documents when new APIs should use direct constructors
vs `*Builder` and when `Default` is expected.
- `cargo x check`, `cargo x test`, and `cargo x lint` pass.
--
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]