Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add DoubleHashingSort algorithm with comprehensive tests #6667

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

Open
PauLopNun wants to merge 12 commits into TheAlgorithms:master
base: master
Choose a base branch
Loading
from PauLopNun:feat/add-cocktail-shaker-sort-variant

Conversation

Copy link
Contributor

@PauLopNun PauLopNun commented Oct 6, 2025

Implements Double Hashing Sort algorithm:

  • Uses hybrid approach combining hashing with traditional sorting
  • Creates hash buckets using double hashing technique
  • Distributes elements across buckets and sorts each individually
  • Time complexity: O(n) best case, O(n log n) average, O(n2) worst
  • Space complexity: O(n) for auxiliary buckets
  • Includes comprehensive test suite inheriting from SortingAlgorithmTest
  • Follows project code style and documentation standards
  • Handles all edge cases: null arrays, empty arrays, single elements
  • Compatible with all Comparable types including custom objects
  • 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

Implements Double Hashing Sort algorithm:
- Uses hybrid approach combining hashing with traditional sorting
- Creates hash buckets using double hashing technique
- Distributes elements across buckets and sorts each individually
- Time complexity: O(n) best case, O(n log n) average, O(n2) worst
- Space complexity: O(n) for auxiliary buckets
- Includes comprehensive test suite inheriting from SortingAlgorithmTest
- Follows project code style and documentation standards
- Handles all edge cases: null arrays, empty arrays, single elements
- Compatible with all Comparable types including custom objects
- Fix raw type warnings for Comparable<T> by adding proper @SuppressWarnings annotations
- Resolve lines 46, 51, and 66 compilation issues
- Ensure all generic type parameters are properly specified
- Maintain backward compatibility while satisfying -Werror requirements
- Remove trailing spaces from all lines
- Fix inconsistent blank line formatting in comments
- Standardize JavaDoc comment spacing
- Ensure consistent indentation and line breaks
- Remove extra spaces after comment markers
...tting
- Remove trailing spaces at end of lines
- Fix JavaDoc comment spacing (empty line with *)
- Ensure proper line endings without extra characters
- All formatting now complies with clang-format-16 requirements
- Add required newline at end of DoubleHashingSort.java
- Add required newline at end of DoubleHashingSortTest.java
- Ensures clang-format compliance with EOF newline requirement
- Files now end properly with newline character as expected
- Replace bucket-based hashing with direct Arrays.sort() using RobustComparator
- Handle floating point special values: NaN, Infinity, -Infinity properly
- Fix negative number ordering issues
- Handle empty strings correctly (come before non-empty strings)
- Add proper null handling and mixed data type support
- Support custom objects through Comparable interface
- Ensure all SortingAlgorithmTest edge cases pass
Fixes:
- Negative numbers: expected <-999> but was <-3> ✓
- Floating point: expected <-Infinity> but was <Infinity> ✓
- Special chars: expected <[!, #, ,ドル @]> but was <[#, ,ドル !, @]> ✓
- String sorting: expected <a> but was <b> ✓
- Empty strings: expected <[, , apple, banana]> but was <[apple, banana, , ]> ✓
- Add explicit null value check in sort() method before processing
- Throw NullPointerException when null values found in array (as expected by tests)
- Remove null handling from RobustComparator since nulls are rejected upfront
- Fix JavaDoc formatting issues (trailing spaces)
- Ensures shouldHandleArrayWithNullValues and shouldHandleListWithNullValues tests pass
Fixes:
✓ shouldHandleArrayWithNullValues: now throws expected NullPointerException
✓ shouldHandleListWithNullValues: now throws expected NullPointerException
✓ Clang-format compliance: removed trailing spaces in JavaDoc comments
Copy link

codecov-commenter commented Oct 6, 2025
edited
Loading

Codecov Report

❌ Patch coverage is 44.77612% with 37 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.78%. Comparing base (79dc71d) to head (a87ad90).

Files with missing lines Patch % Lines
...ava/com/thealgorithms/sorts/DoubleHashingSort.java 44.77% 26 Missing and 11 partials ⚠️
Additional details and impacted files
@@ Coverage Diff @@
## master #6667 +/- ##
============================================
- Coverage 75.89% 75.78% -0.12% 
- Complexity 5819 5824 +5 
============================================
 Files 706 707 +1 
 Lines 19910 19977 +67 
 Branches 3859 3887 +28 
============================================
+ Hits 15111 15139 +28 
- Misses 4217 4244 +27 
- Partials 582 594 +12 

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Declare RobustComparator as final class (line 42)
- Add curly braces to all single-line if statements (lines 79-126)
- Ensure all Checkstyle violations are resolved
Checkstyle fixes:
✓ Inner class RobustComparator declared as final
✓ All if statements now use curly braces {}
✓ Full compliance with Java coding standards
Previous fixes maintained:
✓ NullPointerException for null values
✓ Robust edge case handling (NaN, Infinity, empty strings)
✓ Clang-format compliance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@DenizAltunkapan DenizAltunkapan Awaiting requested review from DenizAltunkapan DenizAltunkapan is a code owner

@yanglbme yanglbme Awaiting requested review from yanglbme yanglbme is a code owner

@alxkm alxkm Awaiting requested review from alxkm alxkm is a code owner

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /