Skip to content

Accept a sentinel of a different type in the parallel ranges set operations - #8250

Open
ArnabOPP wants to merge 1 commit into
TheHPXProject:masterfrom
ArnabOPP:fix-set-ops-par-sentinel
Open

ArnabOPP wants to merge 1 commit into
TheHPXProject:masterfrom
ArnabOPP:fix-set-ops-par-sentinel

Conversation

@ArnabOPP

Copy link
Copy Markdown

Fixes #8249

Proposed Changes

  • In set_union.hpp, set_intersection.hpp, set_difference.hpp and set_symmetric_difference.hpp, declare the end of each chunk in the per-chunk lambda f2 as Iter1/Iter2 instead of Sent1/Sent2. detail::set_operation() calls the lambda with chunk-end iterators (first1 + end1, first2 + end2), which only converted to the parameter type when the sentinel type happened to equal the iterator type. With a par/par(task) policy (which requires a sized sentinel) and any other sentinel type the iterator/sentinel overloads were ill-formed; seq was fine.
  • Add set_operations_sentinel_range, which runs all four operations with a sized sentinel of a different type under seq, par and both task policies and compares the output with std::set_union, std::set_intersection, std::set_difference and std::set_symmetric_difference.

Any background context you want to provide?

The change is 8 lines plus the new test. A minimal reproducer is in #8249.

It does not touch the code that #7933 changes (the input iterators returned by set_operation()), so the two should not conflict.

Tested locally (Debug, GCC 15.2, -std=c++23): the new test fails to compile on the original headers (no match for call to ... set_operation.hpp:139) and passes with the change; set_union_range, set_intersection_range, set_difference_range, set_symmetric_difference_range, includes_range and merge_range still pass. Not tried with clang/MSVC. No clang-format was available here, so lines were wrapped by hand; I will push any formatting fixes CI asks for as a normal commit.

I used Claude Code to help find this bug, write the fix and the test, and write this description, and I reviewed the diff.

Checklist

  • I have fixed a bug and have added a regression test.

…ations

The per-chunk lambdas of set_union, set_intersection, set_difference and
set_symmetric_difference declared the end of each chunk as Sent1/Sent2,
but set_operation() calls them with chunk-end iterators (first1 + end1).
That only compiles when the sentinel type equals the iterator type, so
the iterator/sentinel overloads with a par or par(task) policy (which
require a sized sentinel) were ill-formed for any other sentinel type,
while seq worked. Declare the chunk ends as Iter1/Iter2.

Add set_operations_sentinel_range, which runs all four operations with
a sized sentinel under seq, par and both task policies and compares the
output with the std:: algorithms.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Arnab Chatterjee <arnabchatterjee281205@gmail.com>
@ArnabOPP
ArnabOPP requested a review from hkaiser as a code owner November 26, 2026 17:55
Copilot AI balanced review requested due to automatic review settings November 26, 2026 17:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Parallel set operations now support ranges whose iterator and end-marker types differ. This applies to union, intersection, difference, and symmetric difference.
  • Tests
    • Added coverage for ranges with a distinct, sized end marker. Results are checked against standard-library algorithms under sequential and parallel execution, including synchronous and task-based calls.

The four parallel ranges set operations now use iterator types for chunk-end parameters. A new registered unit test checks their iterator/sentinel overloads with a distinct sized sentinel across sequential, parallel, and task-based policies.

Changes: Parallel set-operation sentinel support

Layer / File(s) Summary
Use iterator types for chunk ends
libs/core/algorithms/include/hpx/parallel/algorithms/set_difference.hpp, libs/core/algorithms/include/hpx/parallel/algorithms/set_intersection.hpp, libs/core/algorithms/include/hpx/parallel/algorithms/set_symmetric_difference.hpp, libs/core/algorithms/include/hpx/parallel/algorithms/set_union.hpp
The parallel chunk lambdas now take Iter1 and Iter2 for chunk ends instead of Sent1 and Sent2.
Test distinct sized sentinels
libs/core/algorithms/tests/unit/container_algorithms/set_operations_sentinel_range.cpp, libs/core/algorithms/tests/unit/container_algorithms/CMakeLists.txt
A registered test compares each ranges set operation with its standard-library counterpart using a distinct sized sentinel and synchronous and task-based policies.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • TheHPXProject/hpx#7933: Changes how detail::set_operation() accumulates consumed input positions for the same four parallel set operations.

Suggested reviewers: msimberg

Merge Risk: Minimal · up to 6981c

This change fixes compilation of the parallel set operations when a sized sentinel of a different type is passed, and adds test coverage. No merge-blocking risk was identified; CI formatting fixes are still pending.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the parallel ranges set operations now accept a sentinel of a different type from the iterator. The changeset fixes the chunk-end parameter types in the four set opera…
Description check Passed The description states the fix in set_union, set_intersection, set_difference and set_symmetric_difference, which matches the raw summary. It also describes the new set_operations_sentinel_range test …
Linked Issues check Passed Issue #8249 requires the iterator/sentinel overloads of set_union, set_intersection, set_difference and set_symmetric_difference to accept a sized sentinel of a different type under par and par(task).…
Out of Scope Changes check Passed All changes match the issue scope: the four set-operation headers (each change limited to the f2 chunk-end parameter types, per the verified set_union.hpp diff and the summary for the other three), on…
Full details: Title check

Explanation

The title names the main change: the parallel ranges set operations now accept a sentinel of a different type from the iterator. The changeset fixes the chunk-end parameter types in the four set operation headers and adds a regression test for that case, so the title matches the primary change.

Full details: Description check

Explanation

The description states the fix in set_union, set_intersection, set_difference and set_symmetric_difference, which matches the raw summary. It also describes the new set_operations_sentinel_range test and gives the test results. It links issue #8249 and explains the cause of the bug.

Full details: Linked Issues check

Explanation

Issue #8249 requires the iterator/sentinel overloads of set_union, set_intersection, set_difference and set_symmetric_difference to accept a sized sentinel of a different type under par and par(task). The cause is the per-chunk lambda f2 declaring chunk ends as Sent1/Sent2, while detail::set_operation() in detail/set_operation.hpp passes chunk-end iterators (first1 + end1, first2 + end2). The head diff of set_union.hpp changes f2 parameters from Sent1/Sent2 to Iter1/Iter2 (verified). The PR summary reports the same 2-line change in set_intersection.hpp, set_difference.hpp and set_symmetric_difference.hpp; these three were not re-read in the diff, so that part rests on the summary. The requested regression test (set_operations_sentinel_range.cpp, registered in container_algorithms/CMakeLists.txt) covers all four operations under seq, par and both task policies and compares against std:: results. The coding requirements are met by the change. The author's local run (fail before, pass after) was not independently re-run.

Full details: Out of Scope Changes check

Explanation

All changes match the issue scope: the four set-operation headers (each change limited to the f2 chunk-end parameter types, per the verified set_union.hpp diff and the summary for the other three), one CMake test registration, and one new regression test file for the four operations. No unrelated code, public declarations or behavior changes are reported. The PR does not touch the set_operation() input-iterator return path referenced in #7933.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e6d20c5e-98c9-4074-9cd5-f923dd3ed94a
Commits

Reviewing files that changed from the base of the PR and between 97e1f27 and 6981ca4.

Files selected for processing: 6

  • libs/core/algorithms/include/hpx/parallel/algorithms/set_difference.hpp
  • libs/core/algorithms/include/hpx/parallel/algorithms/set_intersection.hpp
  • libs/core/algorithms/include/hpx/parallel/algorithms/set_symmetric_difference.hpp
  • libs/core/algorithms/include/hpx/parallel/algorithms/set_union.hpp
  • libs/core/algorithms/tests/unit/container_algorithms/CMakeLists.txt
  • libs/core/algorithms/tests/unit/container_algorithms/set_operations_sentinel_range.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants