Document hash() limitations in BucketSort; add tests showing distribution behavior#6511
Closed
Leogricci wants to merge 8 commits intoTheAlgorithms:masterfrom
Closed
Document hash() limitations in BucketSort; add tests showing distribution behavior#6511Leogricci wants to merge 8 commits intoTheAlgorithms:masterfrom
Leogricci wants to merge 8 commits intoTheAlgorithms:masterfrom
Conversation
distribution behavior
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #6511 +/- ##
============================================
+ Coverage 75.10% 75.11% +0.01%
Complexity 5571 5571
============================================
Files 685 685
Lines 19307 19307
Branches 3732 3732
============================================
+ Hits 14500 14502 +2
+ Misses 4245 4244 -1
+ Partials 562 561 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Author
|
Took a while to get the clang-format right but it should be good now. |
Member
There was a problem hiding this comment.
Is there any reason why you didn't put your Tests in the exististing BucketSortTest ? @Leogricci
Author
There was a problem hiding this comment.
Since the issue only related to the particular case of the hash function i thought it might be better to create another test class, but I realize now it just makes it harder to find. Sorry for the inconvenience, I will modify it now.
Member
|
@Leogricci still working on it? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relates to #6503
distribution behavior
Context
Documents the behavior and limitations of
hash()inBucketSort. The current logic treatscompareToas if it returned a numeric distance. For numerics,compareToyields only -1/0/1 (order), and for non-numeric types (e.g.,String) the magnitude reflects lexicographic code-point differences rather than proportional spacing. Sorting remains correct due to per-bucket sorting and concatenation, but the resulting bucket distribution is not a meaningful proportional mapping.Changes
hash()explaining limitations and the degeneratemin == maxcase.BucketSortHashBehaviorTestto demonstrate:compareTois sign-only).Observed output (examples)
All-equal case -> bucket index: 0
Value 10 -> bucket 0
Value 20 -> bucket 3
Value 30 -> bucket 3
Value 40 -> bucket 3
Value "apple" -> bucket 0
Value "banana" -> bucket 1
Value "carrot" -> bucket 3
Notes
No algorithm/signature change; documentation + tests only (for learners).
clang-format -i --style=file path/to/your/file.java