Skip to content

Code for LowestSetBitManipulation added #5574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

ishanki19-pixel
Copy link

Pull Request: Added LowestSetBit Class for Efficient Bit Manipulation( Fix: #5567)

Description

This pull request introduces the LowestSetBit class, which provides efficient methods for isolating and clearing the lowest set bit of an integer using bitwise operations.

Key Features

  • isolateLowestSetBit(int n): Returns the value of the lowest set bit in the given integer.
  • clearLowestSetBit(int n): Returns the integer with its lowest set bit cleared.

Edge Case Handling

  • Handles the case when n = 0 by returning 0 (no set bits).
  • Works correctly with both positive and negative integers.

Performance Analysis

  • Time Complexity: Both methods operate in constant time O(1) due to direct bitwise operations.
  • Space Complexity: The space complexity is O(1), as no additional space is used beyond the input variable.

Checklist

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java.

@codecov-commenter
Copy link

codecov-commenter commented Oct 5, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 53.98%. Comparing base (87871ef) to head (5fc6418).

Files with missing lines Patch % Lines
...om/thealgorithms/bitmanipulation/LowestSetBit.java 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #5574      +/-   ##
============================================
+ Coverage     53.96%   53.98%   +0.01%     
- Complexity     3387     3390       +3     
============================================
  Files           535      536       +1     
  Lines         15429    15432       +3     
  Branches       2942     2942              
============================================
+ Hits           8327     8331       +4     
  Misses         6749     6749              
+ Partials        353      352       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@prayas7102
Copy link
Contributor

@ishanki19-pixel The PR for which you're providing a fix already had clearLowestSetBit(int n) from it's initial commits, and it already handles corner cases like 0s and negative numbers.

@ishanki19-pixel
Copy link
Author

ishanki19-pixel commented Oct 5, 2024

@ishanki19-pixel The PR for which you're providing a fix already had clearLowestSetBit(int n) from it's initial commits, and it already handles corner cases like 0s and negative numbers.

@prayas7102 Yeah, I was bit confused with testing stuff, I am resolving this in a while.

@ishanki19-pixel ishanki19-pixel force-pushed the feature_lowestsetbits branch 2 times, most recently from b74a362 to e2398ba Compare October 5, 2024 06:34
@ishanki19-pixel
Copy link
Author

@prayas7102 Please review this once again!

@prayas7102
Copy link
Contributor

prayas7102 commented Oct 5, 2024

@prayas7102 Please review this once again!

@ishanki19-pixel The PR for which you're providing a fix already had clearLowestSetBit(int n) from it's initial commits, and it already handles corner cases like 0s and negative numbers.

Hey @ishanki19-pixel I'm not the reviewer for this repository; I'm also a contributor. What I was asking is, all the changes you've made in this PR are already present in PR #5567. So, what is the purpose of this PR?

@ishanki19-pixel
Copy link
Author

@prayas7102 Please review this once again!

@ishanki19-pixel The PR for which you're providing a fix already had clearLowestSetBit(int n) from it's initial commits, and it already handles corner cases like 0s and negative numbers.

Hey @ishanki19-pixel I'm not the reviewer for this repository; I'm also a contributor. What I was asking is, all the changes you've made in this PR are already present in PR #5574. So, what is the purpose of this PR?

But this pr is itself #5574 , its id is itself 5574. I am not able to understand what are you trying to saying because you are referring the same PR in which you are commenting now

@prayas7102
Copy link
Contributor

@prayas7102 Please review this once again!

@ishanki19-pixel The PR for which you're providing a fix already had clearLowestSetBit(int n) from it's initial commits, and it already handles corner cases like 0s and negative numbers.

Hey @ishanki19-pixel I'm not the reviewer for this repository; I'm also a contributor. What I was asking is, all the changes you've made in this PR are already present in PR #5574. So, what is the purpose of this PR?

But this pr is itself #5574 , its id is itself 5574. I am not able to understand what are you trying to saying because you are referring the same PR in which you are commenting now

Sorry for the confusion, it's #5567 which i was trying to refer.

@ishanki19-pixel ishanki19-pixel marked this pull request as ready for review October 7, 2024 13:36
Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

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

Please resolve conflicts

Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution!

@github-actions github-actions bot added the stale label Nov 10, 2024
Copy link

Please reopen this pull request once you have made the required changes. If you need help, feel free to ask in our Discord server or ping one of the maintainers here. Thank you for your contribution!

@github-actions github-actions bot closed this Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants