https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112017-10-15T16:54:06ZRuby Issue Tracking SystemRuby master - Bug #14017: Hash.sort_by inconsistent between 2.2.6 and upper versionshttps://bugs.ruby-lang.org/issues/14017?journal_id=672552017-10-15T16:54:06Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>Ruby 2.2 is in the security maintenance phase, see <a href="https://bugs.ruby-lang.org/projects/ruby/wiki/ReleaseEngineering" class="external">https://bugs.ruby-lang.org/projects/ruby/wiki/ReleaseEngineering</a></p>
<p>As this is not a security issue, it is not suitable for backporting to ruby 2.2.</p> Ruby master - Bug #14017: Hash.sort_by inconsistent between 2.2.6 and upper versionshttps://bugs.ruby-lang.org/issues/14017?journal_id=672562017-10-15T16:57:54Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>chucke (Tiago Cardoso) wrote:</p>
<blockquote>
<p>The bug occurs when sorting by a numeric value and two different keys have similar values: It is very easily demonstrated here:</p>
</blockquote>
<p>It is not a bug.</p>
<blockquote>
<p>For the record, newer rubies present the correct version IMO, as the order of equivalent values shouldn't be changed based on the same value.</p>
</blockquote>
<p>Ruby's sort method is not stable sort.</p>
<p>The documentation of <code>Array#sort_by!</code>:</p>
<blockquote>
<p>The result is not guaranteed to be stable. When two keys are equal,<br>
the order of the corresponding elements is unpredictable.</p>
</blockquote> Ruby master - Bug #14017: Hash.sort_by inconsistent between 2.2.6 and upper versionshttps://bugs.ruby-lang.org/issues/14017?journal_id=672572017-10-15T17:11:35Zchucke (Tiago Cardoso)
<ul></ul><p>got it, forgot to check the doc. Thx for clearing that up!</p> Ruby master - Bug #14017: Hash.sort_by inconsistent between 2.2.6 and upper versionshttps://bugs.ruby-lang.org/issues/14017?journal_id=672582017-10-15T17:34:40Zduerst (Martin Dürst)duerst@it.aoyama.ac.jp
<ul></ul><p>nobu (Nobuyoshi Nakada) wrote:</p>
<blockquote>
<p>Ruby's sort method is not stable sort.</p>
<p>The documentation of <code>Array#sort_by!</code>:</p>
<blockquote>
<p>The result is not guaranteed to be stable. When two keys are equal,<br>
the order of the corresponding elements is unpredictable.</p>
</blockquote>
</blockquote>
<p>Just to be cristal clear:</p>
<p>A sort being stable means that when values are the same, the elements stay in the original order.<br>
This would mean that the order is predictable.<br>
But "the order of the corresponding elements is unpredictable" is stronger, it also inplies that the order can change across versions or implementations, or (at least in theory) across invocations.</p>