Skip to content

feat: optimize SortUtils.swap by skipping operations for equal indices #5266

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

Merged
merged 7 commits into from
Jun 29, 2024
Merged

feat: optimize SortUtils.swap by skipping operations for equal indices #5266

merged 7 commits into from
Jun 29, 2024

Conversation

alxkm
Copy link
Contributor

@alxkm alxkm commented Jun 29, 2024

Adding check if indeces are not equals, for swap method in SortUtils.

According to this suggestion #5265 (comment)

  • 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 Jun 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 39.96%. Comparing base (20e7a3a) to head (5193a9d).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #5266      +/-   ##
============================================
+ Coverage     39.94%   39.96%   +0.01%     
- Complexity     2456     2458       +2     
============================================
  Files           519      519              
  Lines         15487    15488       +1     
  Branches       2957     2957              
============================================
+ Hits           6187     6190       +3     
+ Misses         9008     9007       -1     
+ Partials        292      291       -1     

☔ 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.

It is a pity that Collections.swap is not directly applicable.

@alxkm
Copy link
Contributor Author

alxkm commented Jun 29, 2024

It is a pity that Collections.swap is not directly applicable.

Yes. Maybe, if all the sorting is in lists. But that looks like perfectionism. But sorting implementations using arrays look more traditional from a computer science perspective.

@alxkm alxkm requested a review from vil02 June 29, 2024 19:11
@vil02 vil02 changed the title Refactoring: Adding a check to the swap method in SortUtils feat: optimize SortUtils.swap by skipping operations for equal indices Jun 29, 2024
@vil02 vil02 merged commit 758df7d into TheAlgorithms:master Jun 29, 2024
5 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.

3 participants