[MacRuby-devel] Ruby sort algorithm

Charles Oliver Nutter headius at headius.com
Mon Jan 31 11:00:06 PST 2011


On Sun, Jan 30, 2011 at 6:19 PM, Morgan Schweers <cyberfox at gmail.com> wrote:
> Greetings,
> Ruby's sort algorithm is quicksort, last I checked, and quicksort is not
> stable (which is the property you're looking for in a sort).  There are a
> bunch of ways around this, including writing your own, but one cute, quick,
> but possibly performance-impairing, approach I've seen (Matz's suggestion)
> is:

FWIW, JRuby originally had a stable Array#sort, but because it was
slower than MRI's unstable sort (and we got bug reports to that
effect) we replaced it with an unstable hybrid sort based on
quicksort. Shortly after we did that, someone raised an issue against
MRI to get it to move to a stable sort :)

As far as I know, MRI hasn't changed yet.

- Charlie


More information about the MacRuby-devel mailing list