Add SampleQuantiles trait and Quantile type for histogram quantile queries#5
Merged
thinkingfish merged 8 commits intomainfrom Apr 6, 2026
Merged
Conversation
Implements histogram#4: adds a shared SampleQuantiles trait for Histogram and SparseHistogram with richer quantile query results. - New Quantile newtype (validated f64 in 0.0..=1.0, implements Ord/Eq) - QuantilesResult with BTreeMap<Quantile, Bucket>, total_count, min, max - SampleQuantiles trait with quantiles() and quantile() methods - Deprecate old percentiles()/percentile() methods (delegate to new API) - Bump version to 1.1.0 https://claude.ai/code/session_01YQAY65y5zF3PdR2uuaypMj
New code uses Error::InvalidQuantile. Deprecated percentiles()/percentile() wrappers map it back to InvalidPercentile for backwards compatibility. https://claude.ai/code/session_01YQAY65y5zF3PdR2uuaypMj
Replace deprecated percentile()/percentiles() calls with quantile()/quantiles() and use Quantile newtype for lookups. https://claude.ai/code/session_01YQAY65y5zF3PdR2uuaypMj
Version bumps should happen in release PRs, not feature PRs. https://claude.ai/code/session_01YQAY65y5zF3PdR2uuaypMj
The since field will be set when the release version is determined. https://claude.ai/code/session_01YQAY65y5zF3PdR2uuaypMj
Feature PRs use <version>-alpha.<revision> format only. Release version bumps are reserved for release PRs. https://claude.ai/code/session_01YQAY65y5zF3PdR2uuaypMj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a new
SampleQuantilestrait andQuantiletype to provide a more robust and ergonomic API for computing quantiles from histograms. The oldpercentiles()andpercentile()methods are deprecated in favor of the new trait-based approach.Key Changes
New
Quantiletype (src/quantile.rs): A validated newtype wrapper for quantile values in the range[0.0, 1.0]. Ensures only valid quantiles (finite, non-NaN, within range) are used, enabling safe implementations ofEqandOrdtraits.New
QuantilesResultstruct: Replaces the simpleVec<(f64, Bucket)>return type with a richer result type that includes:BTreeMap<Quantile, Bucket>New
SampleQuantilestrait: Provides a unified interface for computing quantiles across different histogram types:quantiles(&self, quantiles: &[f64]) -> Result<Option<QuantilesResult>, Error>quantile(&self, quantile: f64) -> Result<Option<QuantilesResult>, Error>(convenience method)HistogramandSparseHistogramDeprecated old API: The
percentiles()andpercentile()methods onHistogramandSparseHistogramare now deprecated with a note to use theSampleQuantilestrait instead. They are reimplemented as thin wrappers around the new trait methods for backward compatibility.Implementation improvements:
BTreeMapHistogramandSparseHistogramNotable Implementation Details
Quantiletype usesto_bits()comparison for equality to safely handle the validated f64 valuesHistogramandSparseHistogramimplementations use the same quantile-finding algorithm with a single pass through bucketsAtomicHistogram(users should callload()first to get a snapshot)https://claude.ai/code/session_01YQAY65y5zF3PdR2uuaypMj