[#1491] bug — Mathieu Bouchard <matju@...>
6 messages
2003/09/01
[#1492] non-blocking mode behavior (Re: bug)
— nobu.nokada@...
2003/09/01
Hi,
[#1512] New tests — Dave Thomas <Dave@...>
I was looking through the new test/ruby/* stuff just now, and notices
6 messages
2003/09/05
[#1533] GC disable / enable question — Torsten Rueger <torsten.rueger@...>
Moi,
7 messages
2003/09/17
[#1534] Re: GC disable / enable question
— nobu.nokada@...
2003/09/17
Hi,
[#1541] How to debug ? — Torsten Rueger <torsten.rueger@...>
Moi,
6 messages
2003/09/19
[#1542] Re: How to debug ?
— ts <decoux@...>
2003/09/19
>>>>> "T" == Torsten Rueger <torsten.rueger@hiit.fi> writes:
[#1551] Hashes as keys — "Nathaniel Talbott" <nathaniel@...>
I was just playing around with Hash#hash and discovered that you can't use a
13 messages
2003/09/23
[#1552] Re: Hashes as keys
— Jim Freeze <jim@...>
2003/09/23
On Wednesday, 24 September 2003 at 6:21:33 +0900, Nathaniel Talbott wrote:
[#1556] ostruct.rb patch — "Nathaniel Talbott" <nathaniel@...>
I've been finding OpenStruct to be very useful lately, and then I discovered
9 messages
2003/09/24
[#1557] Re: ostruct.rb patch
— "NAKAMURA, Hiroshi" <nahi@...>
2003/09/24
Hi, Nathaniel,
Re: Hashes as keys
From:
Eugene Scripnik <Eugene.Scripnik@...>
Date:
2003-09-24 15:02:35 UTC
List:
ruby-core #1566
Christoph wrote:
>>$ cat myhash.rb
>>class MyHash < Hash
>> def hash
>> current = 17
>> self.each do |k, v|
>> current = current * 37 + k.hash
>> current = current * 37 + v.hash
>> end
>
>
> Your Hash is not (in this case each enumerate) order independent
> either (i.e. it's possible that hash1 == hash2 is true but
> hash1.hash == hash2.hash is false) - just use a simple summation
> on the key-value pair similar to my previous post
>
> def hash
> inject(17) {|hsh,pair| hsh + pair[0]^(pair[1]<< 2) }
> end
Yes, you are right. This was just a fast dirty example of redefining
#hash method. BTW, you have to use pair[0].hash instead of pair[0] and
pair[1].hash similiarly. And think about collisions that your hash
method will generate, I think it is too simple.
--
Eugene Scripnik
IT Group
Software Architect
Tel./Fax +380 (372) 58-43-10
email: Eugene.Scripnik@itgrp.net
http://www.itgrp.net/