You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Dan Kinder (JIRA)" <ji...@apache.org> on 2009/05/21 02:43:45 UTC

[jira] Issue Comment Edited: (THRIFT-511) Better performing hash method for generated structs

    [ https://issues.apache.org/jira/browse/THRIFT-511?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12711432#action_12711432 ] 

Dan Kinder edited comment on THRIFT-511 at 5/20/09 5:42 PM:
------------------------------------------------------------

turns out ruby arrays hash by item, two different arrays with the same elements have the same hashcode, but otherwise the hashes are very random-looking. Does it seem like there would be a problem with this?:

   def hash
      field_values = []
      each_field do |fid, field_info|
        name = field_info[:name]
        field_values << self.instance_variable_get("@#{name}")
      end
      field_values.hash
    end

      was (Author: dkinder):
    turns out ruby arrays hash by item, two different arrays with the same elements have the same hashcode, but otherwise the hashes are very random-looking. Does it seem like there would be a problem with this?:

  def hash
      struct_fields.values.sort.hash 
  end
  
> Better performing hash method for generated structs
> ---------------------------------------------------
>
>                 Key: THRIFT-511
>                 URL: https://issues.apache.org/jira/browse/THRIFT-511
>             Project: Thrift
>          Issue Type: New Feature
>          Components: Library (Ruby)
>            Reporter: Bryan Duxbury
>            Assignee: Dan Kinder
>             Fix For: 0.2
>
>
> As discussed in THRIFT-231, ruby generated structs' hash code method just always returns zero. While this is semantically correct, it leads to hashes having O(n) performance instead of O(1), which is critical for some applications. 
> We can either take the approach that the Java library uses (optionally produce complex hash function), or just generate a good hash all the time.

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