Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > random bug in the & (set intersection) operator in Arrays

Reply
Thread Tools

random bug in the & (set intersection) operator in Arrays

 
 
Jean-Christophe Le Lann
Guest
Posts: n/a
 
      11-06-2010
Hi

I think I have discovered a random bug in the & (set intersection)
operator in Arrays.

It statistically appeared 37 times out of 200 executions of my program.

on version ruby 1.9.1p376 (2009-12-07 revision 26041) [i686-linux]
on version ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]

I cannot deliver this full program (a source to source compiler) but
here is a example :

array1 = [#<While:0x8a15808>,
#<Say:0x8b0c2c0 @str="2_1a">,
#<Say:0x8b0c25c @str="2_1b">,
#<If:0x8b0c1d0 @body=[#<Say:0x8b0c054 @str="2_1c">], @cond=true>]
========================================
array2 = [#<Say:0x8b0c2c0 @str="2_1a">,
#<Say:0x8b0c25c @str="2_1b">,
#<If:0x8b0c1d0 @body=[#<Say:0x8b0c054 @str="2_1c">], @cond=true>,
#<While:0x8b0c02c,
#<If:0x8b0bb2c @body=[#<Say:0x8b0baa0 @str="2_3">], @cond=true>,
#<Else:0x8b0ba78 @body=[#<Say:0x8b0b94c @str="2_3">]>]
========================================
array1 & array2 sometimes gives things like :

[#<While:0x8a15808 >,
#<Say:0x8b0c2c0 @str="2_1a">,
#<Say:0x8b0c25c @str="2_1b">,
#<If:0x8b0c1d0 @body=[#<Say:0x8b0c054 @str="2_1c">], @cond=true>]

while the expected result is

[#<Say:0x8b0c2c0 @str="2_1a">,
#<Say:0x8b0c25c @str="2_1b">,
#<If:0x8b0c1d0 @body=[#<Say:0x8b0c054 @str="2_1c">], @cond=true>]

How can I report that ? Thx
JCLL
(ps : using Set instead of Array, this works perfectly)





 
Reply With Quote
 
 
 
 
Ryan Davis
Guest
Posts: n/a
 
      11-06-2010


On Nov 6, 2010, at 9:08 AM, Jean-Christophe Le Lann =
<(E-Mail Removed)> wrote:

> How can I report that ?


Just as you did, but with a code repro. Send it to ruby-core@ or file a =
ticket on redmine.=

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      11-06-2010
On 06.11.2010 17:08, Jean-Christophe Le Lann wrote:
> Hi
>
> I think I have discovered a random bug in the& (set intersection)
> operator in Arrays.
>
> It statistically appeared 37 times out of 200 executions of my program.
>
> on version ruby 1.9.1p376 (2009-12-07 revision 26041) [i686-linux]
> on version ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
>
> I cannot deliver this full program (a source to source compiler) but
> here is a example :
>
> array1 = [#<While:0x8a15808>,
> #<Say:0x8b0c2c0 @str="2_1a">,
> #<Say:0x8b0c25c @str="2_1b">,
> #<If:0x8b0c1d0 @body=[#<Say:0x8b0c054 @str="2_1c">], @cond=true>]
> ========================================
> array2 = [#<Say:0x8b0c2c0 @str="2_1a">,
> #<Say:0x8b0c25c @str="2_1b">,
> #<If:0x8b0c1d0 @body=[#<Say:0x8b0c054 @str="2_1c">], @cond=true>,
> #<While:0x8b0c02c,
> #<If:0x8b0bb2c @body=[#<Say:0x8b0baa0 @str="2_3">], @cond=true>,
> #<Else:0x8b0ba78 @body=[#<Say:0x8b0b94c @str="2_3">]>]
> ========================================
> array1& array2 sometimes gives things like :
>
> [#<While:0x8a15808>,
> #<Say:0x8b0c2c0 @str="2_1a">,
> #<Say:0x8b0c25c @str="2_1b">,
> #<If:0x8b0c1d0 @body=[#<Say:0x8b0c054 @str="2_1c">], @cond=true>]
>
> while the expected result is
>
> [#<Say:0x8b0c2c0 @str="2_1a">,
> #<Say:0x8b0c25c @str="2_1b">,
> #<If:0x8b0c1d0 @body=[#<Say:0x8b0c054 @str="2_1c">], @cond=true>]
>
> How can I report that ? Thx
> JCLL
> (ps : using Set instead of Array, this works perfectly)


Well, Set's implementation and Array's are different. I believe Array
does not use #hash while Set does to efficiently find equivalent
instances. Can you show the code for Say#eql?, Say#hash and Say#==
(same for all other classes whose instances are put into your Arrays)?
I am not convinced yet that you found a bug.

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
Reply With Quote
 
Jean-Christophe Le Lann
Guest
Posts: n/a
 
      11-07-2010
Le 07/11/2010 11:40, Robert Klemme a écrit :
>> Hi
>>
>> I think I have discovered a random bug in the& (set intersection)
>> operator in Arrays.
>>

>
> Well, Set's implementation and Array's are different. I believe Array
> does not use #hash while Set does to efficiently find equivalent
> instances. Can you show the code for Say#eql?, Say#hash and Say#==
> (same for all other classes whose instances are put into your Arrays)?
> I am not convinced yet that you found a bug.
>

Hello Robert

I have no such methods. I simply though that the object IDs would be
used for the intersection of the two arrays. Am I wrong ? Thx for your
time and explanations !

Regards
JCLL



 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      11-07-2010
On 07.11.2010 12:06, Jean-Christophe Le Lann wrote:
> Le 07/11/2010 11:40, Robert Klemme a écrit :


>>> I think I have discovered a random bug in the& (set intersection)
>>> operator in Arrays.

>>
>> Well, Set's implementation and Array's are different. I believe Array
>> does not use #hash while Set does to efficiently find equivalent
>> instances. Can you show the code for Say#eql?, Say#hash and Say#==
>> (same for all other classes whose instances are put into your Arrays)?
>> I am not convinced yet that you found a bug.


> I have no such methods. I simply though that the object IDs would be
> used for the intersection of the two arrays. Am I wrong ? Thx for your
> time and explanations !


As long as you define equivalence solely based on object identity you do
not need specific implementations of #hash and #eql?. You can find a
bit of explanation here

http://blog.rubybestpractices.com/po...ete_Class.html

Still it would be good if you could provide a simple test case that
reproduces the problem. You need that for a bug report anyway.

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Math.random() and Math.round(Math.random()) and Math.floor(Math.random()*2) VK Javascript 15 05-02-2010 03:43 PM
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
random.random(), random not defined!? globalrev Python 4 04-20-2008 08:12 AM
*bug* *bug* *bug* David Raleigh Arnold Firefox 12 04-02-2007 03:13 AM
doucmentation bug or bug? p or q for numerical arrays Alan G Isaac Python 3 07-30-2004 02:02 AM



Advertisments