Skip to content

Add mean() to borrowed CumulativeRO Ref views#21

Merged
thinkingfish merged 3 commits into
mainfrom
claude/add-mean-streaming-reducer-ZH3g3
May 19, 2026
Merged

Add mean() to borrowed CumulativeRO Ref views#21
thinkingfish merged 3 commits into
mainfrom
claude/add-mean-streaming-reducer-ZH3g3

Conversation

@thinkingfish

Copy link
Copy Markdown
Member

Summary

  • Adds a public, non-allocating mean() to the borrowed CumulativeROHistogramRef<'a> and CumulativeROHistogram32Ref<'a> views.
  • The owned type caches the midpoint-based mean at construction; the borrowed view doesn't store it, so it computes from the borrowed slices on each call. This lets a zero-alloc streaming reducer holding a borrowed Ref fold the mean in directly without materializing an owned histogram.
  • Returns None for an empty histogram, matching the owned mean().

Versioning

Per CLAUDE.md, this feature PR bumps to 1.5.0-alpha.1 (additive public API → minor bump over the 1.4.0 release commit in this branch's lineage). CHANGELOG updated under [Unreleased].

Test plan

  • cargo test --lib — 118 passed
  • cargo clippy --lib — clean
  • Added parity tests: ref_mean_parity_u64, ref_mean_parity_u32, ref_mean_empty_is_none (owned vs. borrowed agreement, empty → None)

https://claude.ai/code/session_01LDxW544z6m39mY9SkMh9XD


Generated by Claude Code

claude added 3 commits May 19, 2026 17:28
Exposes a public, non-allocating mean() on CumulativeROHistogramRef and
CumulativeROHistogram32Ref so a zero-alloc streaming reducer holding a
borrowed Ref can fold the midpoint-based mean in directly. The owned type
caches the mean at construction; the borrowed view computes it from the
borrowed slices on each call.

https://claude.ai/code/session_01LDxW544z6m39mY9SkMh9XD
Expose mean() as a cheap field access on the borrowed Ref views, mirroring
count(), instead of streaming the midpoint computation on every call. The
owned type's as_ref()/From impls pass their already-cached mean through, so
the hot path does no recomputation; slice-only constructors compute it once.

The Ref types now carry an f64 and so no longer derive Eq (PartialEq kept).

https://claude.ai/code/session_01LDxW544z6m39mY9SkMh9XD
@thinkingfish thinkingfish marked this pull request as ready for review May 19, 2026 17:48
@thinkingfish thinkingfish merged commit 5b08a9c into main May 19, 2026
6 checks passed
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