-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat: add Swap Odd and Even Bits algorithm #964
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
feat: add Swap Odd and Even Bits algorithm #964
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #964 +/- ##
=======================================
Coverage 95.62% 95.62%
=======================================
Files 338 339 +1
Lines 22052 22078 +26
=======================================
+ Hits 21088 21113 +25
- Misses 964 965 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@siriak, this is ready to be merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a new Swap Odd and Even Bits algorithm to the bit manipulation module. The algorithm swaps bits at even positions (0, 2, 4, 6, etc.) with bits at odd positions (1, 3, 5, 7, etc.) in a 32-bit unsigned integer using bitwise masks and shifts. The implementation achieves O(1) time and space complexity.
Key Changes
- Implements
swap_odd_even_bitsfunction using bitwise operations with masks 0xAAAAAAAA and 0x55555555 - Adds comprehensive unit tests covering edge cases including all bits set, alternating patterns, and powers of two
- Includes formatting improvements to DIRECTORY.md for consistency in naming conventions
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/bit_manipulation/swap_odd_even_bits.rs | New algorithm implementation with function documentation and comprehensive unit tests |
| src/bit_manipulation/mod.rs | Adds module declaration and public export for the new algorithm |
| DIRECTORY.md | Adds entry for the new algorithm; includes unrelated formatting improvements for consistency (e.g., "N-Queens", "ROT13", "AES") |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
siriak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
Description
Adds the Swap Odd and Even Bits algorithm to the bit manipulation module.
This algorithm swaps the odd and even bits of a 32-bit unsigned integer using bitwise operations.
Implementation Details
Testing
cargo testcargo fmtChecklist
cargo fmtcargo clippy