https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112013-07-31T12:48:16ZRuby Issue Tracking SystemRuby master - Feature #8707: Hash#reverse_eachhttps://redmine.ruby-lang.org/issues/8707?journal_id=407692013-07-31T12:48:16Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li></ul><p>Do we really need it? What is use-cases?</p>
<p>Matz.</p> Ruby master - Feature #8707: Hash#reverse_eachhttps://redmine.ruby-lang.org/issues/8707?journal_id=407702013-07-31T14:29:14ZAnonymous
<ul></ul><p>Matz: This is quite a significant performance improvement and therefore I think it is worthwhile.</p> Ruby master - Feature #8707: Hash#reverse_eachhttps://redmine.ruby-lang.org/issues/8707?journal_id=407732013-07-31T16:23:16Zduerst (Martin Dürst)duerst@it.aoyama.ac.jp
<ul></ul><p>Hello Charlie,</p>
<p>On 2013/07/31 14:24, Charlie Somerville wrote:</p>
<blockquote>
<p>Matz: This is quite a significant performance improvement and therefore I think it is worthwhile.</p>
</blockquote>
<p>Only if the new method is actually used in practice.<br>
That's why Matz is asking for use cases.</p>
<p>Regards, Martin.</p> Ruby master - Feature #8707: Hash#reverse_eachhttps://redmine.ruby-lang.org/issues/8707?journal_id=410242013-08-09T19:34:12Zko1 (Koichi Sasada)
<ul><li><strong>Assignee</strong> set to <i>matz (Yukihiro Matsumoto)</i></li></ul> Ruby master - Feature #8707: Hash#reverse_eachhttps://redmine.ruby-lang.org/issues/8707?journal_id=410622013-08-10T18:19:23Zfunny_falcon (Yura Sokolov)funny.falcon@gmail.com
<ul></ul><p>Hash in Ruby1.9+ is hash table + double linked list - this is classic structure for LRU cache.</p>
<p>Simple LRU cache could be build with:</p>
<pre><code>class LRU
def initialize
@hash = {}
end
def []=(k, v)
@hash.delete k
@hash[k] = v
end
def [](k)
if v = @hash.delete k
@hash[k] = v
end
v
end
def first
@hash.first
end
def shift
@hash.shift
end
# saves tail items until first stale item signaled
def drop_stale
save = true
stale = []
@hash.reverse_each{|k, v|
unless save && yield(k, v)
save = false
v = @hash.delete k
stale << [k, v]
end
}
stale
end
end
</code></pre>
<p>So that, reverse_each is very critical to be fast at this point</p> Ruby master - Feature #8707: Hash#reverse_eachhttps://redmine.ruby-lang.org/issues/8707?journal_id=447892014-01-30T06:17:07Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>Target version</strong> changed from <i>2.1.0</i> to <i>2.2.0</i></li></ul> Ruby master - Feature #8707: Hash#reverse_eachhttps://redmine.ruby-lang.org/issues/8707?journal_id=461812014-04-11T18:24:22Ztrans (Thomas Sawyer)
<ul></ul><p>Can <code>#reverse</code> be an Enumerator?</p> Ruby master - Feature #8707: Hash#reverse_eachhttps://redmine.ruby-lang.org/issues/8707?journal_id=693202018-01-05T21:00:41Znaruse (Yui NARUSE)naruse@airemix.jp
<ul><li><strong>Target version</strong> deleted (<del><i>2.2.0</i></del>)</li></ul> Ruby master - Feature #8707: Hash#reverse_eachhttps://redmine.ruby-lang.org/issues/8707?journal_id=1029342023-04-27T20:28:43Zbughit (bug hit)
<ul></ul><blockquote>
<p>Do we really need it? What is use-cases?</p>
</blockquote>
<p>When you have an ordered collection it seems self evident that you may need to iterate in reverse. This would for example back a performant <code>last(n = 1)</code> method (<a class="issue tracker-2 status-1 priority-4 priority-default" title="Feature: Hash#first, Hash#last (Open)" href="https://redmine.ruby-lang.org/issues/12165">#12165</a>)</p>
<p>Would you demand to know why one may want the last n elements of an array? These are both ordered collections, if <code>last(n = 1)</code> makes sense for one, it makes sense for the other.</p>
<p><del>Why is this closed with a status of "Feedback"?</del><br>
It seems all feedback issues are labeled as closed which seems confusing.</p> Ruby master - Feature #8707: Hash#reverse_eachhttps://redmine.ruby-lang.org/issues/8707?journal_id=1029482023-04-28T14:38:50Zbughit (bug hit)
<ul></ul><p>Another point is that that hash.reverse_each already exists via enumerable, but with a highly suboptimal array conversion. If it didn't exist you could perhaps debate whether it should be added, but that's moot at this point. The only question here is whether hash.reverse_each should be a hidden perf land-mine or have an optimal implementation for a Hash. Seems like a no-brainer.</p> Ruby master - Feature #8707: Hash#reverse_eachhttps://redmine.ruby-lang.org/issues/8707?journal_id=1029502023-04-30T13:05:29Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/102950/diff?detail_id=64803">diff</a>)</li></ul>