I found this recent discussion interesting in a somewhat related
manner, dealing with hash tables:
http://groups.google.com/group/nodejs/browse_thread/thread/d34ed2ec3526db5a



On Fri, Dec 30, 2011 at 9:02 AM, Robert Klemme
<shortcutter / googlemail.com> wrote:
> On Fri, Dec 30, 2011 at 12:47 AM, Nikolai Weibull <now / bitwi.se> wrote:
>> On Fri, Dec 30, 2011 at 00:26, Robert Klemme <shortcutter / googlemail.com> wrote:
>>
>>> Easy way:
>>
>> I seem to have failed in communicating what I√ő after.  wasn√’ after
>> different ways of implementing #hash, I was after the golden standard
>> of #hash implementations for value objects. o, again, what√‘ the
>> standard way of implementing #hash for value objects in Ruby?
>
> I have covered this a bit earlier:
> http://blog.rubybestpractices.com/posts/rklemme/018-Complete_Class.html
>
> Boils down to that the hash code should be derived from hash codes of
> all fields used as key fields in determining equivalence.
>
>> If there isn√’ one, perhaps one should be agreed upon?
>
> Why do you think a standard is needed? here are some well known
> requirements for good hash codes and how they are calculated and since
> most of the time Hash keys are from the same class whatever algorithm
> chosen works.
>
>> One suggestion would be the XOR of the hash values of the object√‘
>> class and its instance variables.
>
> Not good, because then the same value in different fields has
> identical influence on the hash code. onsequently likelihood of
> collisions increases and thus performance of Hash storage and
> retrieval may decrease.
>
>> Another is the XOR of the hash value of the object√‘ class and the
>> hash value of an Array containing its instance variables.
>
> Better because that considers position.
>
> But still, I don't see the need. ote also that a proper Hash key
> usually should be immutable because changing them causes all sorts of
> trouble if not done carefully. nd most of the time Hash keys are
> String, Symbol, Fixnum and the like - which all do have their #hash
> implementation already.
>
> Kind regards
>
> robert
>
>
> --
> remember.guy do |as, often| as.you_can - without end
> http://blog.rubybestpractices.com/
>