https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112011-08-02T16:32:57ZRuby Issue Tracking SystemRuby master - Feature #5123: Alias Hash 1.9 as OrderedHashhttps://redmine.ruby-lang.org/issues/5123?journal_id=199762011-08-02T16:32:57Zznz (Kazuhiro NISHIYAMA)
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>matz (Yukihiro Matsumoto)</i></li></ul> Ruby master - Feature #5123: Alias Hash 1.9 as OrderedHashhttps://redmine.ruby-lang.org/issues/5123?journal_id=199772011-08-02T16:54:21Zadgar (Michael Edgar)michael.j.edgar@dartmouth.edu
<ul></ul><p>As a corollary, for a few months I had one portion of my code which used Sets, and relied on the fact that Sets in 1.9 retain their order because they in turn use a Hash. The only real way I could document this requirement was to put comments in capital letters in the relevant portions of code so that I didn't forget that I relied on this behavior.</p>
<p>If I had been creating "OrderedSets" (though this sounds too close to SortedSet despite meaning something different), and OrderedSets use an OrderedHash, then it would have been clear in the code that insertion order was preserved, especially for developers new to 1.9.</p>
<p>I like this idea.</p> Ruby master - Feature #5123: Alias Hash 1.9 as OrderedHashhttps://redmine.ruby-lang.org/issues/5123?journal_id=200212011-08-03T10:29:40Ztrans (Thomas Sawyer)
<ul></ul><p>IWon't this break orderedhash gem?</p>
<p>In any case, now that Hash preserves order, why would anyone ever think about changing it back and break old code?</p> Ruby master - Feature #5123: Alias Hash 1.9 as OrderedHashhttps://redmine.ruby-lang.org/issues/5123?journal_id=200322011-08-03T16:23:06Zyeban (Anurag Priyam)anurag08priyam@gmail.com
<ul></ul><blockquote>
<p>It would be nice if the ordered Hash in Ruby 1.9 was aliased as OrderedHash.<br>
That way people who rely on preserving the insertion order in some application (me, for example) could explicitly use OrderedHash, and developers of Ruby would be free to redefine Hash in future versions if a better implementation that a doubly-linked circular list is found.<br>
(I read something about a possibility of using "red–black tree".)</p>
</blockquote>
<p>This sounds like one of those variable names with a type prefixed to<br>
it, like sequence_string, or sequence_array. They look ugly. It would<br>
have mad more sense if Ruby were ever to ship with two different Hash<br>
implementations. Besides, the aliasing can be done at the application<br>
level too. So if the Hash implementation changes tomorrow, you are<br>
free to re-alias to some other ordered hash implementation.</p>
<p>--<br>
Anurag Priyam<br>
<a href="http://about.me/yeban/" class="external">http://about.me/yeban/</a></p> Ruby master - Feature #5123: Alias Hash 1.9 as OrderedHashhttps://redmine.ruby-lang.org/issues/5123?journal_id=201352011-08-07T07:23:07Zalexeymuranov (Alexey Muranov)
<ul></ul><p>Thomas Sawyer wrote:</p>
<blockquote>
<p>IWon't this break orderedhash gem?</p>
<p>In any case, now that Hash preserves order, why would anyone ever think about changing it back and break old code?</p>
</blockquote>
<p>To improve performance, for example, or to restore the original meaning of "hash".</p>
<p>Alexey Muranov.</p> Ruby master - Feature #5123: Alias Hash 1.9 as OrderedHashhttps://redmine.ruby-lang.org/issues/5123?journal_id=201362011-08-07T07:24:43Zalexeymuranov (Alexey Muranov)
<ul></ul><p>Anurag Priyam wrote:</p>
<blockquote>
<p>Besides, the aliasing can be done at the application<br>
level too. So if the Hash implementation changes tomorrow, you are<br>
free to re-alias to some other ordered hash implementation.</p>
</blockquote>
<p>But then i will have to edit my code to upgrade to a new version of Ruby.</p>
<p>Alexey Muranov.</p>
<hr>
<p><em>Update 2011-11-09.</em> "It would have made more sense if Ruby were ever to ship with two different Hash implementations." -- Anurag Priyam<br>
Why not? Implementing Hash and OrderedHash separately some day (50 years from now) may gain some speed for pure Hash.</p>
<p><em>Update 2011-12-04.</em> This is where i first read about red-black trees for hash: <a href="http://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/" class="external">http://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/</a></p>
<p><em>Update 2012-05-04.</em> I still like my original proposal because the use of <code>OrderedHash</code> constant documents the behavior, but if it is not accepted, another way to use unordered "faster" hashes would be to call them <code>OptimizedHash</code>, and have a method <code>Hash#optimized</code> for conversion:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"> <span class="n">a</span> <span class="o">=</span> <span class="p">{}.</span><span class="nf">optimized</span>
</code></pre>
<p>With the original proposal, the method would be <code>Hash#ordered</code>:</p>
<pre><code> b = {}.ordered
</code></pre> Ruby master - Feature #5123: Alias Hash 1.9 as OrderedHashhttps://redmine.ruby-lang.org/issues/5123?journal_id=318122012-10-28T00:00:35Zyhara (Yutaka HARA)
<ul><li><strong>Category</strong> set to <i>core</i></li><li><strong>Target version</strong> set to <i>2.6</i></li></ul> Ruby master - Feature #5123: Alias Hash 1.9 as OrderedHashhttps://redmine.ruby-lang.org/issues/5123?journal_id=321222012-11-01T05:09:56Zheadius (Charles Nutter)headius@headius.com
<ul></ul><p>The decision is already made. Hash has been ordered since 1.9.1 (or 1.9.2?) and changing it now would break all code that expects ordering. Ordering also does not necessarily limit options for implementation...it just makes certain implementations less efficient.</p>
<p>There's a separate bug still being evaluated to add RBTree to core...perhaps that would fulfill what you need?</p> Ruby master - Feature #5123: Alias Hash 1.9 as OrderedHashhttps://redmine.ruby-lang.org/issues/5123?journal_id=321252012-11-01T05:29:41Zalexeymuranov (Alexey Muranov)
<ul></ul><p>I was only proposing an alias for now. Maybe <code>OHash</code>, <code>OSet</code>?</p> Ruby master - Feature #5123: Alias Hash 1.9 as OrderedHashhttps://redmine.ruby-lang.org/issues/5123?journal_id=556672015-12-19T11:43:54Zalexeymuranov (Alexey Muranov)
<ul></ul><p>I have just stumbled upon this: the <a href="http://facebook.github.io/immutable-js/" class="external">Immutable collections for JavaScript</a> has both <code>Map</code> and <a href="http://facebook.github.io/immutable-js/docs/#/OrderedMap" class="external"><code>OrderedMap</code></a>.</p>
<p>One more: in Haskell, there are <a href="https://hackage.haskell.org/package/containers" class="external">containers</a> and <a href="https://hackage.haskell.org/package/unordered-containers" class="external">unordered-containers</a>.</p> Ruby master - Feature #5123: Alias Hash 1.9 as OrderedHashhttps://redmine.ruby-lang.org/issues/5123?journal_id=704742018-02-20T08:19:08Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Rejected</i></li></ul><p>Today, everyone knows Ruby's Hash is a OrderedHash.</p>
<p>Matz.</p>