Forum: IronRuby Bug filed: Array#hash should properly handle recursive arrays

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1c29f9b1bf5f1b88ed8b0c9a9be39788?d=identicon&s=25 Daniele Alessandri (Guest)
on 2009-04-16 23:22
(Received via mailing list)
Hi,

I have just filed this bug on CodePlex:
http://ironruby.codeplex.com/WorkItem/View.aspx?Wo...

It is actually pretty easy to fix with a bunch of lines of code in
RubyArray.GetHashCode (just tested, too bad IronRuby.dll is not open
to contributions) and, as a result, this would resolve the following 4
critical failures for the array core specs:

Array#hash properly handles recursive arrays
Array#| properly handles recursive arrays
Array#uniq properly handles recursive arrays
Array#uniq! properly handles recursive arrays

Regards

--
Daniele Alessandri
http://www.clorophilla.net/blog/
http://twitter.com/JoL1hAHN
Aea6cfe04952626ab630bde47ff82f89?d=identicon&s=25 Shri Borde (Guest)
on 2009-04-17 00:09
(Received via mailing list)
I can fix RubyArray.GetHashCode to handle the simple case of an array
containing itself.

However, the simple fix wont deal with the case where the array is
indirectly recursive as in this snippet.
  a = []
  b = [a]
  a<<b
Aea6cfe04952626ab630bde47ff82f89?d=identicon&s=25 Shri Borde (Guest)
on 2009-04-17 00:24
(Received via mailing list)
Curt pointed out a way to fix the recursive case using
RubyUtils.RecursionTracker...
1c29f9b1bf5f1b88ed8b0c9a9be39788?d=identicon&s=25 Daniele Alessandri (Guest)
on 2009-04-17 00:30
(Received via mailing list)
Great, that's exactly what I used :-)

Thanks


On Fri, Apr 17, 2009 at 00:22, Shri Borde <Shri.Borde@microsoft.com>
wrote:
> However, the simple fix wont deal with the case where the array is indirectly recursive 
as in this snippet.
> Hi,
> Array#| properly handles recursive arrays
> Ironruby-core mailing list
> Ironruby-core@rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
>



--
Daniele Alessandri
http://www.clorophilla.net/blog/
http://twitter.com/JoL1hAHN
Cb51033949ffccd982ae32c9f890f25a?d=identicon&s=25 Tomas Matousek (Guest)
on 2009-04-17 01:15
(Received via mailing list)
Does Ruby call "hash" dynamically on each element of the array?
If not then there is no need for RecursionTracker. A simple
non-recursive DFS with a dictionary that remembers visited objects
should do.

Tomas
Cb51033949ffccd982ae32c9f890f25a?d=identicon&s=25 Tomas Matousek (Guest)
on 2009-04-17 01:16
(Received via mailing list)
See RubyFileOps.Join for an example.

Tomas
F983f0c990cba2fe743ef62a975ec99c?d=identicon&s=25 Curt Hagenlocher (Guest)
on 2009-04-17 04:01
(Received via mailing list)
The simple test I did suggested that MRI dynamically calls hash on each
element of the array.
This topic is locked and can not be replied to.