Skip to content

Add Java implementation of the h2 histogram#1

Merged
thinkingfish merged 3 commits into
mainfrom
claude/java-h2histogram-yehb0p
Jul 10, 2026
Merged

Add Java implementation of the h2 histogram#1
thinkingfish merged 3 commits into
mainfrom
claude/java-h2histogram-yehb0p

Conversation

@thinkingfish

Copy link
Copy Markdown
Member

A pure-Java implementation of the iopsystems h2 histogram, using the Rust histogram crate as the reference and mirroring the code organization and README structure of the Go and Python ports.

What's included

  • Config — bucketing parameters, valueToIndex / indexToLowerBound / indexToUpperBound, totalBuckets, error, plus fromTotalBuckets for inferring the grouping power from a bare bucket count (Rezolus parquet files).
  • Histogram — dense histogram: increment, record, recordMany, percentile(s), merge, subtract, downsample, toSparse, toCumulative, fromBuckets.
  • SparseHistogram — columnar (index, count) form (the Rezolus :bucket_indices / :bucket_counts layout): fromHistogram, fromParts, toDense, toCumulative.
  • CumulativeHistogram — read-only cumulative form (the crate's CumulativeROHistogram): binary-search percentile(s), precomputed midpoint-estimated mean, bucketQuantileRange, bucketsWithQuantiles.
  • Bucket / PercentileResult / BucketWithQuantiles — value types (Java records).

Design notes

  • Values and counts are u64 carried in Java longs with unsigned semantics (Long.compareUnsigned, Long.numberOfLeadingZeros, >>>), so the full u64 range is supported, exactly like the Rust crate and the Go port.
  • Maven build targeting Java 17, no runtime dependencies; JUnit 5 for tests; CI matrix over JDK 17 and 21.
  • Version starts at 0.1.0-SNAPSHOT; the README documents the release flow.

Correctness

  • The test suite ports the exact assertion vectors from the Rust crate's own unit tests (src/config.rs), the same approach used by the Go and Python ports. 36 tests, all passing.
  • Additionally cross-checked valueToIndex / bucket bounds against the Go implementation over 40,000 random values spanning the full u64 range (grouping powers 3 and 7): zero mismatches.

🤖 Generated with Claude Code

https://claude.ai/code/session_016Bb8BttJZHuy6zh957NMGT


Generated by Claude Code

A pure-Java port of the iopsystems h2 histogram, producing byte-for-byte
identical bucketing to the Rust histogram crate. Mirrors the code
organization of the Go and Python implementations:

- Config: bucketing parameters and value<->index conversions
- Histogram: dense histogram with record/percentile/merge/subtract/downsample
- SparseHistogram: columnar (index, count) form for storage
- CumulativeHistogram: read-only cumulative form with O(log n) percentiles
  and a precomputed midpoint-estimated mean
- Bucket / PercentileResult / BucketWithQuantiles value types

Values and counts are u64 carried in Java longs with unsigned semantics,
so the full u64 range is supported. The bucketing math is verified against
the exact assertions from the Rust crate's own unit tests (src/config.rs).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016Bb8BttJZHuy6zh957NMGT
claude added 2 commits July 10, 2026 02:02
Single-threaded record-path benchmark at matched relative-error levels
(h2 grouping powers 3/7/14 vs HDR 1/2/4 significant digits), with value
streams touching from 64 buckets up to the full counter array to stress
different cache levels.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016Bb8BttJZHuy6zh957NMGT
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016Bb8BttJZHuy6zh957NMGT
@thinkingfish
thinkingfish marked this pull request as ready for review July 10, 2026 14:58
@thinkingfish
thinkingfish merged commit 6357594 into main Jul 10, 2026
2 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