-
Notifications
You must be signed in to change notification settings - Fork 20.5k
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
Add DoubleHashingSort algorithm with comprehensive tests #6667
Conversation
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(n²) 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
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6667 +/- ##
============================================
- Coverage 76.60% 76.50% -0.11%
- Complexity 6026 6031 +5
============================================
Files 719 720 +1
Lines 20326 20393 +67
Branches 3937 3965 +28
============================================
+ Hits 15571 15601 +30
- Misses 4164 4190 +26
- Partials 591 602 +11 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- 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
The implementation named While the comparator handles edge cases like NaN, infinities, strings, and numbers, the actual sorting algorithm is TimSort, which already exists in the repository Since this PR does not introduce a new sorting algorithm and the functionality is largely redundant, it cannot be merged. The name |
Implements Double Hashing Sort algorithm:
clang-format -i --style=file path/to/your/file.java