Rust
Rust copied to clipboard
feat: Added Stable Matching Algorithm
feat: Added Stable Matching Algorithm
Description
This commit introduces the Stable Matching Algorithm, commonly known as the Gale-Shapley Algorithm, to the codebase. It solves the problem of matching two sets (e.g., men and women) based on preference lists, ensuring that the final matching is stable—meaning no two individuals would rather be paired with each other than with their current partners.
Type of change
- [x] New feature (non-breaking change which adds functionality)
Checklist:
- [x] I ran bellow commands using the latest version of rust nightly.
- [x] I ran
cargo clippy --all -- -D warningsjust before my last commit and fixed any issue that was found. - [x] I ran
cargo fmtjust before my last commit. - [x] I ran
cargo testjust before my last commit and all tests passed. - [x] I added my algorithm to the corresponding
mod.rsfile within its own folder, and in any parent folder(s). - [x] I added my algorithm to
DIRECTORY.mdwith the correct link. - [x] I checked
COUNTRIBUTING.mdand my code follows its guidelines.
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 95.36%. Comparing base (
209c1b4) to head (d9b140c). Report is 1 commits behind head on master.
Additional details and impacted files
@@ Coverage Diff @@
## master #806 +/- ##
==========================================
+ Coverage 95.31% 95.36% +0.05%
==========================================
Files 310 311 +1
Lines 22430 22673 +243
==========================================
+ Hits 21380 21623 +243
Misses 1050 1050
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Please add the missing tests. We are aiming to 100% coverage.
done it reached 100% convergence
@vil02 @imp2002 ready for review
@sozelfist could you take a look? Do you have some reasonable idea how to refactor stable_matching into smaller pieces?
@sozelfist could you take a look? Do you have some reasonable idea of how to refactor
stable_matchinginto smaller pieces?
Sure, I will propose decomposing the stable_matching function into helper functions that handle the separated logic and make the main function more streamlined and focused.
Btw, why don't we write tests using macros? It makes the test more compact and we can suggest adding some edge tests.
What do you think about the refactor, @vil02 and @BKarthik7?
What do you think about the refactor, @vil02 and @BKarthik7?
I understood the refactor and is nice but if a newbie wants to understand the code i thought the original version was more readable it's just my opinion I am open to hear your point of view too. I implemented the changes and pushed it.
The original version might be easier for beginners due to its linear structure, but the refactored version is better in terms of maintainability and best practices.
@sozelfist done is there any thing else
I just proposed the refactored version of your code. Maybe @vil02 would have something to propose.
Btw, why don't we write tests using macros? It makes the test more compact and we can suggest adding some edge tests.
You can consider this one for tests