-
Notifications
You must be signed in to change notification settings - Fork 27
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
radix sort fallback to Base on small input #51
Closed
LilithHafner
wants to merge
11
commits into
JuliaCollections:master
from
LilithHafner:radix-sort-small-fallback
Closed
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ae551b7
radix sort fallback to Base on small input
LilithHafner ee9a5a8
increase test input size to cover radixsort
LilithHafner f3190d4
Update src/SortingAlgorithms.jl
LilithHafner 6a9b226
Test smaller & larger inputs
LilithHafner b662767
Update src/SortingAlgorithms.jl
LilithHafner 5f005a7
Handle default arguments manualy
LilithHafner edb805c
Update Project.toml
LilithHafner 95fb8ea
Cover uncommon branches of radix_sort
LilithHafner 4bc1464
Rollback consistent exception testing
LilithHafner 97030b0
whitespace
LilithHafner c507f37
fix tests
LilithHafner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need
ts
as an argument here, right? I'm not aware of anywhere that passes their ownts
, for example. I think we just movets = similar(vs)
down below the length check.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use it in #33, but indeed I've no idea why it's supported here given that it's not used. Anyway better leave this for another PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah OK you mention this because of the addition of the length check. Indeed better move this inside the function then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not aware of very many users of
SortingAlgorithms
, but I imagine one might desire to pass ints
when sorting multiple arrays to avoid allocations and save time. For example:With results
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that it's not clear whether this is part of the public API or not. In doubt, maybe we should keep it to avoid breaking things.
But I don't think we should silently resize
ts
disregarding its size. The cleanest solution would probably to usenothing
as the default. Otherwise, we could allow 0-lengthts
as a special case, but that's a bit less clean (and that's one more allocation).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the now-current edb805c version is as strict as before the PR: throws a bounds error if
ts
orvs
fail to contain all oflo:hi
and otherwise messes with the contents ofts
but not its size.I also think the current API is identical to the old: one may pass in a correctly sized
ts
or leave that argument off.Theoretically, the only changes this PR makes are:
hi-lo
is small radix sort is not run, and no allocations are made.ts
needs to be allocated (almost always) an OffsetVector spanninglo:hi
is allocated instead of a fullsimilar(vs)
Perhaps 2 and 3 belong in a different PR, but I think both are reasonable (assuming OffsetVectors are implemented as efficiently as Vectors)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the use of an
OffsetArray
is free:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using an
OffsetArray
is clever. Though that will only make a significant difference iflo:hi
covers a relatively small part ofvs
. AFAICT this will only happen when there are lots ofNaN
s (viafpsort!
), right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is also the only case I'm aware of. Do you still think it's worth it? It adds a dependency on OffsetArrays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not if that's the only situation where it happens.