Skip to content

Conversation

@BKarthik7
Copy link
Contributor

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

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I ran bellow commands using the latest version of rust nightly.
  • I ran cargo clippy --all -- -D warnings just before my last commit and fixed any issue that was found.
  • I ran cargo fmt just before my last commit.
  • I ran cargo test just before my last commit and all tests passed.
  • I added my algorithm to the corresponding mod.rs file within its own folder, and in any parent folder(s).
  • I added my algorithm to DIRECTORY.md with the correct link.
  • I checked COUNTRIBUTING.md and my code follows its guidelines.

@codecov-commenter
Copy link

codecov-commenter commented Oct 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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              

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

Copy link
Member

@vil02 vil02 left a comment

Choose a reason for hiding this comment

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

Please add the missing tests. We are aiming to 100% coverage.

@BKarthik7 BKarthik7 marked this pull request as draft October 5, 2024 17:23
@BKarthik7 BKarthik7 marked this pull request as ready for review October 5, 2024 17:50
@BKarthik7
Copy link
Contributor Author

Please add the missing tests. We are aiming to 100% coverage.

done it reached 100% convergence

@BKarthik7 BKarthik7 requested a review from vil02 October 5, 2024 18:08
@BKarthik7 BKarthik7 marked this pull request as draft October 5, 2024 18:45
@BKarthik7 BKarthik7 marked this pull request as ready for review October 5, 2024 19:04
@BKarthik7
Copy link
Contributor Author

BKarthik7 commented Oct 5, 2024

@vil02 @imp2002 ready for review

@vil02
Copy link
Member

vil02 commented Oct 6, 2024

@sozelfist could you take a look? Do you have some reasonable idea how to refactor stable_matching into smaller pieces?

@sozelfist
Copy link
Contributor

@sozelfist could you take a look? Do you have some reasonable idea of how to refactor stable_matching into 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.

@sozelfist
Copy link
Contributor

Btw, why don't we write tests using macros? It makes the test more compact and we can suggest adding some edge tests.

@sozelfist
Copy link
Contributor

What do you think about the refactor, @vil02 and @BKarthik7?

@BKarthik7
Copy link
Contributor Author

BKarthik7 commented Oct 7, 2024

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.

@sozelfist
Copy link
Contributor

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.

@BKarthik7
Copy link
Contributor Author

@sozelfist
done is there any thing else

@sozelfist
Copy link
Contributor

I just proposed the refactored version of your code. Maybe @vil02 would have something to propose.

@sozelfist
Copy link
Contributor

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

Copy link
Member

@vil02 vil02 left a comment

Choose a reason for hiding this comment

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

I think we can leave it as it is.

@vil02 vil02 merged commit 0dbaff5 into TheAlgorithms:master Oct 10, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants