Skip to content
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

ENH add an introsort implementation #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hayd
Copy link

@hayd hayd commented Oct 25, 2014

This is an implementation from the pseudo-code in Musser's paper.

I haven't done any performance testing, no doubt there is optimization to do here e.g. @inbounds and something better for index_of_median_of_three (which atm is terrible)...


function sort!(v::AbstractVector, lo::Int, hi::Int, a::IntroSortAlg, o::Ordering)
N = length(v)
if N > 1
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this guard should rather be on hi - lo > 1 (which can cause an exception due to log2(...) == -Inf).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, I wonder what this comment meant...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's referring to the line below, and I think that's right. Care to submit a pull request?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this line should just be hi-li > 1, will see if that works and push an update commit here.

Any thoughts on optimizations for index_of_median_of_three ?

@stevengj
Copy link
Contributor

What's the advantage of introsort?

@kmsquire
Copy link
Member

I haven't looked at this yet, but generally, introsort uses quick sort,
but keeps track of recursion depth, and if it reaches a certain depth,
switches to a different algorithm with guaranteed worst case depth of O(log
N).

It's a good algorithm to have available.

On Monday, October 27, 2014, Steven G. Johnson [email protected]
wrote:

What's the advantage of introsort?


Reply to this email directly or view it on GitHub
#7 (comment)
.

@xiaodaigh
Copy link

it's been more than 5 years. close it, merge it, or start another repo

@nalimilan
Copy link
Contributor

There's an unresolved comment above that somebody needs to address (and also needs a rebase). (BTW, necro-posting generally isn't useful if you're not volunteering to work on PRs yourself.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants