Expand description
Domain-agnostic distribution-control primitives: bounded top-K sampling, group-aware quota
fill, and coverage classification. No knowledge of any particular record type – callers
supply plain closures (bucket_key_fn, group_key_fn) to map their own domain’s rows onto
the generic FeatureKey/BucketKey/GroupKey string concepts used here.
Structs§
- Group
Aware Fill Result - Outcome of
group_aware_fill: kept items (original input order) plus the diversity/quota stats a caller typically wants to report (e.g. in a run manifest). - Heap
Entry - One candidate in a bounded top-K stream.
keycarries every tie-break the equivalent full-materialize-then-sort_bycode would apply;indexis always the final tiebreak layer, reproducingsort_by’s stability – which a heap has no notion of on its own, since two records can otherwise agree on every fieldkeycompares.recordis left generic (R) rather than fixed to any one domain’s row type, so this heap is reusable outside shogiesa. - Quota
Spec - A hand-editable quota file: observed (or desired) per-bucket target counts.
quotas’ keys are caller-defined bucket-key strings, reused verbatim (not trimmed/reparsed) so there is never a second representation of “what bucket is this” that could drift from the first.bymakes the file self-describing: a caller reconstructs its own bucketing dimensions from this field alone, never from separately-passed flags, so an apply-time mismatch between flags and file is structurally impossible. - Total
F32 f32wrapper with a total order (viatotal_cmp) for callers ranking by a plain fraction (e.g. a 0..=1 quality score) that is never NaN in practice but has noOrdimpl of its own.
Enums§
- Bucket
Status - Coverage classification for one bucket in an enumerated bucket space – e.g. “every
phase x side x eval-bucket combination”, where a combination nobody observed still needs a
verdict (
Missing), not just silent absence from a tally.
Functions§
- bucket_
floor - floor(value / bucket_size) * bucket_size.
bucket_size == 0is a caller error, expected to be checked and rejected at the caller’s entry point, not deep inside this pure helper. - classify_
bucket - Ratio-to-mean classification:
count == 0is alwaysMissing; otherwiseUnder/Overwhencountfalls outside[under_ratio, over_ratio] * mean, elseOk. - group_
aware_ fill - Group-aware bounded-heap quota fill: streams
itemsonce, assigns each a bucket viabucket_key_fn, and – among items whose bucket has a quota inquotas– fills that bucket’s quota preferring group diversity (group_key_fn) over first-come-first-served. - mean_of
- push_
bounded - Keeps the
countsmallestHeapEntrys seen so far – the standard bounded-heap top-K algorithm: push while under capacity, otherwise evict the current worst-kept entry ifentryranks ahead of it. Provably identical final set (and, viaBinaryHeap::into_sorted_vec, identical order) to “collect everything, sort ascending by the same key, truncate” – at O(count) memory instead of O(n). - reservoir_
sample - Bounded top-K reservoir sample: keeps
countitems keyed byseeded_hash(seed, key_fn(item)), restoring original input order in the result (an A-Res-style weighted reservoir sample, streamed at O(count) memory instead of materializing the whole input). - seeded_
hash - Deterministic hash of
(seed, s)– the tie-breaking/spreading mechanism bounded top-K sampling uses to pick “which items” deterministically. Each part is hashed with an explicit length prefix so a naive concatenation can’t collide across the seed/string boundary.
Type Aliases§
- Bucket
Key - A composite bucket identifier a caller’s sampling/coverage quota is keyed on.
- Feature
Key - A single dimension’s value for one record (e.g. a phase name, a side name) – callers compose
these into a
BucketKeyhowever their domain defines “bucket”. - Group
Key - Identifies which correlated group (e.g. one source game) a record belongs to, for group-aware sampling that keeps one group from consuming an entire bucket’s quota.