Skip to content

Align theta and tuple JaccardSimilarity; check theta seeds in tuple set operations - #782

Merged
leerho merged 1 commit into
mainfrom
jaccard-seed-and-tuple-clamp
Oct 29, 2026
Merged

leerho merged 1 commit into
mainfrom
jaccard-seed-and-tuple-clamp

Conversation

@leerho

@leerho leerho commented Oct 28, 2026

Copy link
Copy Markdown
Member

Follow-up to #778. It brings the Java theta and tuple JaccardSimilarity classes into line with each other, and with C++ (theta_jaccard_similarity_base.hpp) and Go (tuple/jaccard_similarity.go), which share one implementation for theta and tuple.

Theta JaccardSimilarity

  • Seed overloads for jaccard, exactlyEqual, similarityTest and dissimilarityTest. Until now, sketches created with a custom seed couldn't be compared: the internal union and intersection used the default seed and threw "Incompatible Seed Hashes". The existing methods pass the default seed through, so callers see no change.

Tuple JaccardSimilarity

  • Shared helpers computeUnion, newUnion and identicalSets, as theta has since Fix JaccardSimilarity.exactlyEqual throwing for small theta sketches #778. They replace four copies of the union-and-compare code.
  • Union size clamped in exactlyEqual to the legal range of nominal entries, as tuple jaccard, theta, C++ and Go already do. Unlike theta, tuple never threw here, because tuple sketches don't enforce the range; the change is for consistency.
  • Same-sketch check added to jaccard(TupleSketch, TupleSketch, ...), as in theta, C++ and Go.

Tuple set operations with a ThetaSketch input

  • TupleUnion.union, TupleIntersection.intersect, TupleAnotB.notB and TupleAnotB.aNotB now throw SketchesArgumentException when given a non-empty ThetaSketch created with a non-default seed. Java tuple sketches always use the default seed, so such input used to give silently wrong results. Empty sketches aren't checked, as in theta.
  • To support this, ThetaSketch.getSeedHash() is now public, matching get_seed_hash() in C++.

Full custom-seed support for Java tuple sketches, as C++, Go and Rust have, is planned as a separate PR.

Tests

  • New tuple/ThetaSeedHashTest, plus new tests in both JaccardSimilarityTest classes. The seed-rejection tests fail without this change.
  • mvn verify passes: 2298 tests, plus the javadoc and style checks.

🤖 Generated with Claude Code

…le set operations

Theta JaccardSimilarity:
- Add seed overloads of jaccard, exactlyEqual, similarityTest and
  dissimilarityTest, as in C++ and Go. Sketches created with a custom
  seed previously could not be compared at all.

Tuple JaccardSimilarity:
- Share the union and identical-sets code through private helpers, as
  theta does, replacing four copies.
- Clamp the union size in exactlyEqual to the legal range of nominal
  entries, as tuple jaccard, theta, C++ and Go already do.
- Return early when jaccard is given the same sketch twice.

Tuple set operations:
- TupleUnion, TupleIntersection and TupleAnotB now reject a non-empty
  ThetaSketch created with a non-default seed. Tuple sketches always use
  the default seed, so such input previously gave silently wrong results.
- ThetaSketch.getSeedHash() is now public, as get_seed_hash() is in C++.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@leerho
leerho requested review from proost and tisonkun October 28, 2026 21:40

@tisonkun tisonkun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@leerho
leerho merged commit 9d8c38b into main Oct 29, 2026
6 checks passed
@leerho
leerho deleted the jaccard-seed-and-tuple-clamp branch October 29, 2026 18:51
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