Skip to content

feat: support theta and tuple a-not-b#155

Merged
tisonkun merged 1 commit into
apache:mainfrom
ariesdevil:tuple-a-not-b
Jul 25, 2026
Merged

feat: support theta and tuple a-not-b#155
tisonkun merged 1 commit into
apache:mainfrom
ariesdevil:tuple-a-not-b

Conversation

@ariesdevil

@ariesdevil ariesdevil commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

based on #152 #153 #154

@ariesdevil
ariesdevil force-pushed the tuple-a-not-b branch 3 times, most recently from e4cbc3f to 2902e5e Compare July 23, 2026 03:26
@ariesdevil ariesdevil closed this Jul 23, 2026
@ariesdevil ariesdevil reopened this Jul 23, 2026
@ariesdevil
ariesdevil force-pushed the tuple-a-not-b branch 9 times, most recently from 32d85e8 to 1d29301 Compare July 24, 2026 15:00
@tisonkun

Copy link
Copy Markdown
Member

#154 is merged now.

I wonder if we'd have a tuple_a_not_b_test.rs integration test. And some common test code may be de-duplicate later.

@ariesdevil
ariesdevil force-pushed the tuple-a-not-b branch 2 times, most recently from 8b9e68f to 373584c Compare July 25, 2026 03:09
Comment thread datasketches/src/tuple/a_not_b.rs
@ariesdevil
ariesdevil marked this pull request as draft July 25, 2026 04:18
@ariesdevil ariesdevil changed the title feat: support tuple a-not-b feat: support theta and tuple a-not-b Jul 25, 2026

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.

I have some ideas on factoring out this test utility support module. Will do once this PR gets merged.

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.

... to avoid too much #[cfg(feature = "...")] and #[allow(dead_code)].

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.

a_not_b comes from datasketches-cpp and datasketches-java?

@leerho @proost what if we name this set operation as difference or exception, since a_not_b is somewhat strange to me. Or is it actually an idiom in this domain?

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.

Based on the result, it looks like the same as set difference.

@ariesdevil What do you think?

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.

a_not_b is a set difference. However the name a_not_b is a mnemonic that tells you the direction of the difference.

In the math of boolean logic one would write

A \ B := A AND NOT B = $A \cup !B$
or
B \ A := B AND NOT A = $B \cup !A$

Where "\" is the difference operator.
Note that A \ B != B \ A !

Although C++ allows user defined operators most languages do not. To call the difference function, we need to indicate the direction. We chose to do it by the position of the arguments, and the name of the function is a mnemonic of the direction.

Sketch result a_not_b(Sketch A, Sketch B);

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.

@leerho Thanks for your information!

Yes the Rust impl also defines the API as:

let update_policy = DefaultUpdatePolicy::<u64>::default();
let mut a = TupleSketchBuilder::new(update_policy).build();
a.update("apple", 1);
a.update("banana", 1);

let mut b = TupleSketchBuilder::new(update_policy).build();
b.update("banana", 1);

let a_not_b = TupleAnotB::default();
let result = a_not_b.compute(&a, &b, true).unwrap();

So I generally agree that a_not_b provides more information and avoid the confusion of op direction.

Even if we can add methods or operator overrides to ThetaSketch/TupleSketch, it is not symmetry to the union and intersection interface.

One minor comment: any typical reason to name it TupleAnotB rather than TupleANotB? Weird CamelCase at first glance.

@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.

Generally LGTM.

Anything keeps this PR a draft before it's ready for review and merge?

@ariesdevil
ariesdevil marked this pull request as ready for review July 25, 2026 08:34

@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.

Minor comments can be handled later.

@tisonkun
tisonkun merged commit 87e9e84 into apache:main Jul 25, 2026
10 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.

4 participants