Skip to content

Fix dichotomy for swe - #103

Merged
schwitzguebel merged 1 commit into
masterfrom
fix_dichoto
Jul 16, 2026
Merged

Fix dichotomy for swe#103
schwitzguebel merged 1 commit into
masterfrom
fix_dichoto

Conversation

@kahyami

@kahyami kahyami commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Please check if the PR fulfills these requirements (please use '[x]' to check the checkboxes, or submit the PR and then click the checkboxes)

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Does this PR already have an issue describing the problem ? If so, link to this issue using '#XXX' and skip the rest

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

What is the current behavior? (You can also link to an open issue here)

What is the new behavior (if this is a feature change)?

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

Other information:

(if any of the questions/checkboxes don't apply, please delete them entirely)

Summary by CodeRabbit

  • Bug Fixes
    • Improved dichotomy range calculations when starting from the maximum value.
    • Refined precision handling to stop searches correctly in edge cases.
    • Improved behavior when valid or invalid boundary values are unavailable.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

HalfRangeDivisionIndexStrategy centralizes invalid-step bound selection for non-minimum-first searches and revises precision termination for asymmetric valid and invalid step states.

Changes

Half-range division strategy

Layer / File(s) Summary
Bound selection and precision termination
farao-dichotomy-api/src/main/java/com/farao_community/farao/dichotomy/api/index/HalfRangeDivisionIndexStrategy.java
The non-startWithMin path uses getInvalidStep(Index) for its upper bound, and precisionReached adds handling for missing invalid steps with an available highest valid step.

Estimated code review effort: 3 (Moderate) | ~15–30 minutes

Possibly related PRs

Poem

A bunny bounds the halfway line,
With invalid steps kept neat and fine.
Precision checks now softly gleam,
Valid peaks guide the searcher’s dream.
Hop, hop—dichotomy’s bright!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: a fix to the dichotomy implementation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix_dichoto

Warning

Tools execution failed with the following error:

Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error)


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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
farao-dichotomy-api/src/main/java/com/farao_community/farao/dichotomy/api/index/HalfRangeDivisionIndexStrategy.java (1)

48-51: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use the local highestValidStep variable instead of calling index.highestValidStep() again.

Line 50 calls index.highestValidStep().getLeft() while the local variable highestValidStep (fetched at line 36 and null-checked at line 47) is already in scope. This is inconsistent with line 47 which uses the local variable, and introduces a potential correctness risk if the Index state changes between calls. Additionally, getInvalidStep(index) internally re-fetches index.lowestInvalidStep() which is already available as the local lowestInvalidStep from line 37.

♻️ Proposed refactor
         } else {
-            return mid(index.highestValidStep().getLeft(), getInvalidStep(index));
+            return mid(highestValidStep.getLeft(), getInvalidStep(index));
         }

For completeness, getInvalidStep could also accept the already-fetched lowestInvalidStep to avoid the redundant index.lowestInvalidStep() call:

-    private double getInvalidStep(Index<T> index) {
-        return index.lowestInvalidStep() != null
-                ? index.lowestInvalidStep().getLeft()
-                : index.maxValue();
+    private double getInvalidStep(Pair<Double, DichotomyStepResult<T>> lowestInvalidStep, double maxValue) {
+        return lowestInvalidStep != null
+                ? lowestInvalidStep.getLeft()
+                : maxValue;
     }

And update the call sites at lines 48 and 50 to pass lowestInvalidStep and maxValue.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@farao-dichotomy-api/src/main/java/com/farao_community/farao/dichotomy/api/index/HalfRangeDivisionIndexStrategy.java`
around lines 48 - 51, Update the affected branch in
HalfRangeDivisionIndexStrategy to use the already-fetched, null-checked
highestValidStep variable instead of calling index.highestValidStep() again.
Also reuse the local lowestInvalidStep by updating getInvalidStep and its call
sites to accept that value, preserving the existing midpoint behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@farao-dichotomy-api/src/main/java/com/farao_community/farao/dichotomy/api/index/HalfRangeDivisionIndexStrategy.java`:
- Around line 48-51: Update the affected branch in
HalfRangeDivisionIndexStrategy to use the already-fetched, null-checked
highestValidStep variable instead of calling index.highestValidStep() again.
Also reuse the local lowestInvalidStep by updating getInvalidStep and its call
sites to accept that value, preserving the existing midpoint behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e5274b9c-64ed-46c8-95bf-2311236f0cdc

📥 Commits

Reviewing files that changed from the base of the PR and between ed9f75c and c9f54d0.

📒 Files selected for processing (1)
  • farao-dichotomy-api/src/main/java/com/farao_community/farao/dichotomy/api/index/HalfRangeDivisionIndexStrategy.java

@schwitzguebel
schwitzguebel merged commit 881b5a5 into master Jul 16, 2026
19 of 28 checks passed
@schwitzguebel
schwitzguebel deleted the fix_dichoto branch July 16, 2026 11:33
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