Skip to content

Add CumulativeROHistogram for fast quantile queries#7

Open
thinkingfish wants to merge 2 commits intomainfrom
claude/plan-cumulative-histogram-2razF
Open

Add CumulativeROHistogram for fast quantile queries#7
thinkingfish wants to merge 2 commits intomainfrom
claude/plan-cumulative-histogram-2razF

Conversation

@thinkingfish
Copy link
Copy Markdown
Member

Summary

Introduces CumulativeROHistogram, a new read-only histogram variant optimized for fast quantile queries using cumulative bucket counts and binary search.

Key Changes

  • New CumulativeROHistogram type: A read-only histogram that stores cumulative counts (running prefix sums) instead of individual bucket counts, enabling O(log n) quantile lookups via binary search
  • Efficient quantile computation: Uses adaptive search strategy—linear scan for small histograms (≤ cache line size) and binary search for larger ones
  • Conversion support: Implements From<&Histogram> and From<&SparseHistogram> for easy construction from existing histogram types
  • Rich iteration API: Provides iter() for bucket enumeration and iter_with_quantiles() to get quantile ranges alongside buckets
  • Quantile range queries: New bucket_quantile_range() method returns the percentile range each bucket represents
  • Comprehensive validation: from_parts() validates index ordering, count monotonicity, and configuration bounds
  • Full test coverage: 13 tests covering conversions, quantile matching, edge cases, and validation

Implementation Details

  • Stores only non-zero buckets in columnar form (index and cumulative count vectors), matching SparseHistogram's space efficiency
  • Implements SampleQuantiles trait for consistent API with other histogram types
  • Individual bucket counts are computed on-the-fly from cumulative differences
  • Supports serialization via serde and JSON schema generation
  • Empty histograms and single-sample cases handled correctly

https://claude.ai/code/session_01TT4hwxFnsHwYthuwR8eTK6

A read-only histogram variant with cumulative (prefix-sum) counts that
enables O(log n) quantile lookups via binary search (with linear scan
fallback for cache-line-sized data). Constructed from Histogram or
SparseHistogram via From impls. Includes quantile range query methods
for analytics use cases.

https://claude.ai/code/session_01TT4hwxFnsHwYthuwR8eTK6
@thinkingfish thinkingfish requested a review from brayniac April 7, 2026 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants