Remove duplicated if checking in add_into_heap for cpu. - #49
Merged
Conversation
5 tasks
hzhangxyz
requested review from
CuSO4Deposit and
Copilot
and removed request for
Copilot
June 24, 2025 11:47
There was a problem hiding this comment.
Pull Request Overview
The PR cleans up redundant checks and braces in the add_into_heap function to simplify its control flow.
- Removed a duplicated empty
if (compare(value, heap[index]))guard - Flattened nested conditional logic for child‐node handling
- Eliminated an extra closing brace
Comments suppressed due to low confidence (1)
qmb/_hamiltonian_cpu.cpp:307
- [nitpick] Consider adding unit tests for the scenario where only the right child is present (this branch) to ensure correct heap behavior.
if (right_present) {
| @@ -261,91 +261,64 @@ void add_into_heap(T* heap, std::int64_t heap_size, const T& value) { | |||
| std::int64_t index = 0; | |||
| if (compare(value, heap[index])) { | |||
| } else { | |||
There was a problem hiding this comment.
[nitpick] Use an early return instead of an empty if‐block to reduce nesting. For example:
if (compare(value, heap[index]))
return;
Suggested change
| } else { | |
| return; | |
| } |
Member
Author
|
@CuSO4Deposit 由于修改compare变量名为less,同时依赖此PR和一个已经merge进main的PR,我打算等这个PR merge了再改名字。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Checklist: