Skip to content

Conversation

Rudra2637
Copy link
Contributor

Description of Change

Updated the countSetBits function in bit_manipulation/count_of_set_bits.cpp to improve type safety and correctness:

  • Changed the input parameter from int64_t to uint64_t to ensure only non-negative numbers are allowed.
  • Changed the internal counter variable count from int to uint64_t to match the return type and prevent any theoretical overflow.
  • Maintains original functionality for normal inputs.

This ensures the function is consistent, safe, and fully aligned with the intended use of counting set bits in non-negative integers.


Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Added documentation so that the program is self-explanatory and educational - Doxygen guidelines
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Notes:
Improves type safety for countSetBits function without changing its behavior for normal inputs.

Copy link
Collaborator

@realstealthninja realstealthninja left a comment

Choose a reason for hiding this comment

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

LGTM

@Rudra2637
Copy link
Contributor Author

I am glad you liked it

@realstealthninja realstealthninja added the approved Approved; waiting for merge label Sep 25, 2025
@realstealthninja realstealthninja merged commit 8541bb3 into TheAlgorithms:master Sep 27, 2025
6 checks passed
@Rudra2637
Copy link
Contributor Author

LGTM

Hey some of the files contain similar kind of problem should i fix them as well ?

@realstealthninja realstealthninja linked an issue Sep 29, 2025 that may be closed by this pull request
realstealthninja added a commit to realstealthninja/C-Plus-Plus that referenced this pull request Oct 1, 2025
…s#3003)

Co-authored-by: realstealthninja <68815218+realstealthninja@users.noreply.github.com>
realstealthninja added a commit to realstealthninja/C-Plus-Plus that referenced this pull request Oct 1, 2025
realstealthninja added a commit to realstealthninja/C-Plus-Plus that referenced this pull request Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Approved; waiting for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Return type inconsistency
2 participants