Skip to content

HLL: harden checks of coupon hash set images; document stringArrHash - #799

Merged
leerho merged 2 commits into
mainfrom
hll-set-hardening
Nov 12, 2026
Merged

leerho merged 2 commits into
mainfrom
hll-set-hardening

Conversation

@leerho

@leerho leerho commented Nov 12, 2026

Copy link
Copy Markdown
Member

This hardens the checks of HLL coupon hash set (SET mode) images, in line with apache/datasketches-cpp#565. It also documents the key hash of the Array of Strings tuple sketch.

HLL SET image checks

HllUtil.checkPreamble(), which heapify, wrap, writableWrap and HllUnion.heapify all call, now also checks a SET image against the limits a valid sketch keeps:

  • Set mode requires lgK ≥ 8.
  • A compact image holds at most 3/4 · 2^(lgK−3) coupons, and the segment is large enough for them.
  • In an updatable image:
    • lgArr (after the existing recompute for early images) is in [LG_INIT_SET_SIZE, lgK−3];
    • the table is at most 3/4 full;
    • the segment is large enough for the table;
    • the coupon count equals the number of non-empty slots.

Valid writers never produce images outside these limits. The sanity checks inside DirectCouponList's promotions skip them, because there the sketch's own list or set is one coupon past its limit for a moment.

Util.stringArrHash javadoc

This is the key hash of the Array of Strings tuple sketch, so other languages need its exact definition:

  • elements are joined with "," without escaping;
  • a null element contributes "null";
  • the joined string is hashed as UTF-16LE code units, with no byte-order mark;
  • the hash is XXH64 with seed 0x7A3CCA71.

Tests

  • HllCorruptImageTest gets six new tests: compact count above the limit, a truncated compact image, updatable lgArr out of range, count not matching the table, an overfull table, and set mode with lgK 7. Each one fails if the new check is removed.
  • A sweep over valid SET images for lgK 8–14, from both heap and direct sketches, checks that they still load on every path.
  • StringArrHashTest checks stringArrHash against the documented definition.

The full suite passes (2,394 tests), and so do the C++, Go and Rust HLL deserialization checks against the local CL files.

🤖 Generated with Claude Code

leerho and others added 2 commits November 11, 2026 16:34
The Array of Strings tuple sketch uses this hash as its key, so other
languages need its exact definition: elements joined with "," without
escaping, a null element as "null", the joined string hashed as UTF-16LE
code units with no byte-order mark, XXH64 with seed 0x7A3CCA71. Adds a
test that checks the method against that definition.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
checkPreamble(), which heapify, wrap, writableWrap and HllUnion.heapify
all call, now also checks a SET image against the limits a valid sketch
keeps:
- set mode requires lgK of at least 8;
- a compact image holds at most 3/4 of 2^(lgK - 3) coupons, and the
  segment holds them;
- in an updatable image lgArr, after the existing recompute for early
  images, is in [LG_INIT_SET_SIZE, lgK - 3], the table is at most 3/4
  full, the segment holds the table, and the count equals the number of
  non-empty slots.

The sanity checks inside DirectCouponList's promotions skip these limits,
because there the sketch's own list or set is one coupon past its limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@leerho
leerho merged commit fe31572 into main Nov 12, 2026
6 checks passed
@leerho
leerho deleted the hll-set-hardening branch November 12, 2026 20: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