You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Bryan Duxbury (JIRA)" <ji...@apache.org> on 2008/12/11 22:56:44 UTC

[jira] Created: (THRIFT-231) Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members

Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members
---------------------------------------------------------------------------------------------

                 Key: THRIFT-231
                 URL: https://issues.apache.org/jira/browse/THRIFT-231
             Project: Thrift
          Issue Type: Bug
          Components: Compiler (Ruby), Library (Ruby)
            Reporter: Bryan Duxbury


Since generated structs don't define a hash method in Ruby, it defaults to a unique number every time. This means that even if two objects have equal values, they will not have equal hashcodes. As a result, if you try to create a set of these structs and subsequently attempt to test membership on an equal struct, it'll always return false. The same problem prevents structs from being used as map keys.

At the very least, we should define a hash method that always returns 0 and leave it up to the chaining to resolve the problem. A slightly more appropriate move would be to have the hashcode of a struct be the composition of its member values.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-231) Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-231?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12657806#action_12657806 ] 

Bryan Duxbury commented on THRIFT-231:
--------------------------------------

I think it's clearly related, but i see making the structs immutable as a complimentary issue. I like the Java approach of trusting the developer, personally.

> Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members
> ---------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-231
>                 URL: https://issues.apache.org/jira/browse/THRIFT-231
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Ruby), Library (Ruby)
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>         Attachments: thrift-231.patch
>
>
> Since generated structs don't define a hash method in Ruby, it defaults to a unique number every time. This means that even if two objects have equal values, they will not have equal hashcodes. As a result, if you try to create a set of these structs and subsequently attempt to test membership on an equal struct, it'll always return false. The same problem prevents structs from being used as map keys.
> At the very least, we should define a hash method that always returns 0 and leave it up to the chaining to resolve the problem. A slightly more appropriate move would be to have the hashcode of a struct be the composition of its member values.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-231) Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members

Posted by "Kevin Clark (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-231?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12656230#action_12656230 ] 

Kevin Clark commented on THRIFT-231:
------------------------------------

Why'd you take out the class check in #== ?

> Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members
> ---------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-231
>                 URL: https://issues.apache.org/jira/browse/THRIFT-231
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Ruby), Library (Ruby)
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>         Attachments: thrift-231.patch
>
>
> Since generated structs don't define a hash method in Ruby, it defaults to a unique number every time. This means that even if two objects have equal values, they will not have equal hashcodes. As a result, if you try to create a set of these structs and subsequently attempt to test membership on an equal struct, it'll always return false. The same problem prevents structs from being used as map keys.
> At the very least, we should define a hash method that always returns 0 and leave it up to the chaining to resolve the problem. A slightly more appropriate move would be to have the hashcode of a struct be the composition of its member values.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (THRIFT-231) Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members

Posted by "Dan Kinder (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-231?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dan Kinder updated THRIFT-231:
------------------------------

    Attachment: thrift231.patch

struct.hash changed, comment removed

> Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members
> ---------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-231
>                 URL: https://issues.apache.org/jira/browse/THRIFT-231
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Ruby), Library (Ruby)
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>         Attachments: thrift-231.patch, thrift231.patch
>
>
> Since generated structs don't define a hash method in Ruby, it defaults to a unique number every time. This means that even if two objects have equal values, they will not have equal hashcodes. As a result, if you try to create a set of these structs and subsequently attempt to test membership on an equal struct, it'll always return false. The same problem prevents structs from being used as map keys.
> At the very least, we should define a hash method that always returns 0 and leave it up to the chaining to resolve the problem. A slightly more appropriate move would be to have the hashcode of a struct be the composition of its member values.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-231) Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-231?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12656252#action_12656252 ] 

Bryan Duxbury commented on THRIFT-231:
--------------------------------------

Proper == semantics only check value equality. That's what eql? is for.

> Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members
> ---------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-231
>                 URL: https://issues.apache.org/jira/browse/THRIFT-231
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Ruby), Library (Ruby)
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>         Attachments: thrift-231.patch
>
>
> Since generated structs don't define a hash method in Ruby, it defaults to a unique number every time. This means that even if two objects have equal values, they will not have equal hashcodes. As a result, if you try to create a set of these structs and subsequently attempt to test membership on an equal struct, it'll always return false. The same problem prevents structs from being used as map keys.
> At the very least, we should define a hash method that always returns 0 and leave it up to the chaining to resolve the problem. A slightly more appropriate move would be to have the hashcode of a struct be the composition of its member values.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (THRIFT-231) Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members

Posted by "Kevin Clark (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-231?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Kevin Clark resolved THRIFT-231.
--------------------------------

    Resolution: Fixed

Ok, pushed without the class check in 731760. Thanks!

> Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members
> ---------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-231
>                 URL: https://issues.apache.org/jira/browse/THRIFT-231
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Ruby), Library (Ruby)
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>         Attachments: thrift-231.patch
>
>
> Since generated structs don't define a hash method in Ruby, it defaults to a unique number every time. This means that even if two objects have equal values, they will not have equal hashcodes. As a result, if you try to create a set of these structs and subsequently attempt to test membership on an equal struct, it'll always return false. The same problem prevents structs from being used as map keys.
> At the very least, we should define a hash method that always returns 0 and leave it up to the chaining to resolve the problem. A slightly more appropriate move would be to have the hashcode of a struct be the composition of its member values.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-231) Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members

Posted by "Esteve Fernandez (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-231?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12657709#action_12657709 ] 

Esteve Fernandez commented on THRIFT-231:
-----------------------------------------

Isn't this same case the as THRIFT-162? I think this functionality can be achieved with type modifiers and make some classes immutable:

struct foo {
  1: i32 bar;
  2: i32 baz;
  3: i32 qux;
  4: i32 bop;
} (
  ruby.immutable = "true",
)

and implement foo#hash. This would give us a reliable hash code, since instance variables couldn't be changed after instantiation.

> Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members
> ---------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-231
>                 URL: https://issues.apache.org/jira/browse/THRIFT-231
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Ruby), Library (Ruby)
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>         Attachments: thrift-231.patch
>
>
> Since generated structs don't define a hash method in Ruby, it defaults to a unique number every time. This means that even if two objects have equal values, they will not have equal hashcodes. As a result, if you try to create a set of these structs and subsequently attempt to test membership on an equal struct, it'll always return false. The same problem prevents structs from being used as map keys.
> At the very least, we should define a hash method that always returns 0 and leave it up to the chaining to resolve the problem. A slightly more appropriate move would be to have the hashcode of a struct be the composition of its member values.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (THRIFT-231) Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-231?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bryan Duxbury updated THRIFT-231:
---------------------------------

    Attachment: thrift-231.patch

Here's a patch that seems to solve the problems for me. What I've done is remove the class equality check from the == method, added a eql? method that includes the class equality check and calls ==, and a placeholder hash method. This fixes Set operations in my limited testing.

> Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members
> ---------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-231
>                 URL: https://issues.apache.org/jira/browse/THRIFT-231
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Ruby), Library (Ruby)
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>         Attachments: thrift-231.patch
>
>
> Since generated structs don't define a hash method in Ruby, it defaults to a unique number every time. This means that even if two objects have equal values, they will not have equal hashcodes. As a result, if you try to create a set of these structs and subsequently attempt to test membership on an equal struct, it'll always return false. The same problem prevents structs from being used as map keys.
> At the very least, we should define a hash method that always returns 0 and leave it up to the chaining to resolve the problem. A slightly more appropriate move would be to have the hashcode of a struct be the composition of its member values.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-231) Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-231?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12656821#action_12656821 ] 

Bryan Duxbury commented on THRIFT-231:
--------------------------------------

instance_variable_get on another struct type will almost definitely return nil for fields they don't have in common, and that's actually the correct behavior for the == semantics. I don't think using respond_to and send would actually add much different behavior.

> Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members
> ---------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-231
>                 URL: https://issues.apache.org/jira/browse/THRIFT-231
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Ruby), Library (Ruby)
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>         Attachments: thrift-231.patch
>
>
> Since generated structs don't define a hash method in Ruby, it defaults to a unique number every time. This means that even if two objects have equal values, they will not have equal hashcodes. As a result, if you try to create a set of these structs and subsequently attempt to test membership on an equal struct, it'll always return false. The same problem prevents structs from being used as map keys.
> At the very least, we should define a hash method that always returns 0 and leave it up to the chaining to resolve the problem. A slightly more appropriate move would be to have the hashcode of a struct be the composition of its member values.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-231) Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members

Posted by "Kevin Clark (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-231?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12656799#action_12656799 ] 

Kevin Clark commented on THRIFT-231:
------------------------------------

Sure, but I'm a little uncomfortable using instance_variable_get if we don't *know* that the other object is of the same type. What do you think? We could use respond_to and send plausibly.

> Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members
> ---------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-231
>                 URL: https://issues.apache.org/jira/browse/THRIFT-231
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Ruby), Library (Ruby)
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>         Attachments: thrift-231.patch
>
>
> Since generated structs don't define a hash method in Ruby, it defaults to a unique number every time. This means that even if two objects have equal values, they will not have equal hashcodes. As a result, if you try to create a set of these structs and subsequently attempt to test membership on an equal struct, it'll always return false. The same problem prevents structs from being used as map keys.
> At the very least, we should define a hash method that always returns 0 and leave it up to the chaining to resolve the problem. A slightly more appropriate move would be to have the hashcode of a struct be the composition of its member values.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (THRIFT-231) Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-231?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bryan Duxbury updated THRIFT-231:
---------------------------------

    Patch Info: [Patch Available]

> Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members
> ---------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-231
>                 URL: https://issues.apache.org/jira/browse/THRIFT-231
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Ruby), Library (Ruby)
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>         Attachments: thrift-231.patch
>
>
> Since generated structs don't define a hash method in Ruby, it defaults to a unique number every time. This means that even if two objects have equal values, they will not have equal hashcodes. As a result, if you try to create a set of these structs and subsequently attempt to test membership on an equal struct, it'll always return false. The same problem prevents structs from being used as map keys.
> At the very least, we should define a hash method that always returns 0 and leave it up to the chaining to resolve the problem. A slightly more appropriate move would be to have the hashcode of a struct be the composition of its member values.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-231) Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members

Posted by "Kevin Clark (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-231?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12657625#action_12657625 ] 

Kevin Clark commented on THRIFT-231:
------------------------------------

>From the rdoc on Object#eql? and friends:

     Equality---At the +Object+ level, +==+ returns +true+ only if _obj_
     and _other_ are the same object. Typically, this method is
     overridden in descendent classes to provide class-specific meaning.

     [snip]

     The +eql?+ method returns +true+ if _obj_ and _anObject_ have the
     same value. Used by +Hash+ to test members for equality. For
     objects of class +Object+, +eql?+ is synonymous with +==+.
     Subclasses normally continue this tradition, but there are
     exceptions. +Numeric+ types, for example, perform type conversion
     across +==+, but not across +eql?

Thrift structs can't be equal unless they're of the same class. Seems odd to take the check out.

instance_variable_get will *almost* definitely return nil for fields they don't have in common... but how about something like:

class Foo
  def initialize(msg)
    @message = msg
  end
end

If Foo and a thrift exception like this exist:

exception Xception {
  1: string message,
}

Equality will work. Which, though unlikely, isn't unheard of.

> Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members
> ---------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-231
>                 URL: https://issues.apache.org/jira/browse/THRIFT-231
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Ruby), Library (Ruby)
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>         Attachments: thrift-231.patch
>
>
> Since generated structs don't define a hash method in Ruby, it defaults to a unique number every time. This means that even if two objects have equal values, they will not have equal hashcodes. As a result, if you try to create a set of these structs and subsequently attempt to test membership on an equal struct, it'll always return false. The same problem prevents structs from being used as map keys.
> At the very least, we should define a hash method that always returns 0 and leave it up to the chaining to resolve the problem. A slightly more appropriate move would be to have the hashcode of a struct be the composition of its member values.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-231) Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-231?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12711683#action_12711683 ] 

Bryan Duxbury commented on THRIFT-231:
--------------------------------------

Hey Dan, what do you think about handling the performance improvements for this issue on THRIFT-511? I'd prefer to keep this issue closed and not add any new patches.

> Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members
> ---------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-231
>                 URL: https://issues.apache.org/jira/browse/THRIFT-231
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Ruby), Library (Ruby)
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>         Attachments: thrift-231.patch, thrift231.patch
>
>
> Since generated structs don't define a hash method in Ruby, it defaults to a unique number every time. This means that even if two objects have equal values, they will not have equal hashcodes. As a result, if you try to create a set of these structs and subsequently attempt to test membership on an equal struct, it'll always return false. The same problem prevents structs from being used as map keys.
> At the very least, we should define a hash method that always returns 0 and leave it up to the chaining to resolve the problem. A slightly more appropriate move would be to have the hashcode of a struct be the composition of its member values.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-231) Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-231?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12655795#action_12655795 ] 

Bryan Duxbury commented on THRIFT-231:
--------------------------------------

Yeah, I just discovered the eql? thing. I'll put up a patch shortly.

> Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members
> ---------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-231
>                 URL: https://issues.apache.org/jira/browse/THRIFT-231
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Ruby), Library (Ruby)
>            Reporter: Bryan Duxbury
>
> Since generated structs don't define a hash method in Ruby, it defaults to a unique number every time. This means that even if two objects have equal values, they will not have equal hashcodes. As a result, if you try to create a set of these structs and subsequently attempt to test membership on an equal struct, it'll always return false. The same problem prevents structs from being used as map keys.
> At the very least, we should define a hash method that always returns 0 and leave it up to the chaining to resolve the problem. A slightly more appropriate move would be to have the hashcode of a struct be the composition of its member values.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-231) Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-231?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12657629#action_12657629 ] 

Bryan Duxbury commented on THRIFT-231:
--------------------------------------

Alright, I'm not completely married to removing the class check. I think in most practical cases, it'll work out just fine, but if it's going to relieve worries, then we can keep the class check in place.

Do you need me to submit a new patch or can you just omit that diff line?

> Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members
> ---------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-231
>                 URL: https://issues.apache.org/jira/browse/THRIFT-231
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Ruby), Library (Ruby)
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>         Attachments: thrift-231.patch
>
>
> Since generated structs don't define a hash method in Ruby, it defaults to a unique number every time. This means that even if two objects have equal values, they will not have equal hashcodes. As a result, if you try to create a set of these structs and subsequently attempt to test membership on an equal struct, it'll always return false. The same problem prevents structs from being used as map keys.
> At the very least, we should define a hash method that always returns 0 and leave it up to the chaining to resolve the problem. A slightly more appropriate move would be to have the hashcode of a struct be the composition of its member values.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (THRIFT-231) Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-231?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bryan Duxbury reassigned THRIFT-231:
------------------------------------

    Assignee: Bryan Duxbury

> Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members
> ---------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-231
>                 URL: https://issues.apache.org/jira/browse/THRIFT-231
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Ruby), Library (Ruby)
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>
> Since generated structs don't define a hash method in Ruby, it defaults to a unique number every time. This means that even if two objects have equal values, they will not have equal hashcodes. As a result, if you try to create a set of these structs and subsequently attempt to test membership on an equal struct, it'll always return false. The same problem prevents structs from being used as map keys.
> At the very least, we should define a hash method that always returns 0 and leave it up to the chaining to resolve the problem. A slightly more appropriate move would be to have the hashcode of a struct be the composition of its member values.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-231) Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members

Posted by "Kevin Clark (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-231?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12655794#action_12655794 ] 

Kevin Clark commented on THRIFT-231:
------------------------------------

If you want this to work, we'll also need to define eql? to return true for equivalent structs.

> Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members
> ---------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-231
>                 URL: https://issues.apache.org/jira/browse/THRIFT-231
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Ruby), Library (Ruby)
>            Reporter: Bryan Duxbury
>
> Since generated structs don't define a hash method in Ruby, it defaults to a unique number every time. This means that even if two objects have equal values, they will not have equal hashcodes. As a result, if you try to create a set of these structs and subsequently attempt to test membership on an equal struct, it'll always return false. The same problem prevents structs from being used as map keys.
> At the very least, we should define a hash method that always returns 0 and leave it up to the chaining to resolve the problem. A slightly more appropriate move would be to have the hashcode of a struct be the composition of its member values.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.