From: George Moschovitis Date: 2006-11-26T03:06:27+09:00 Subject: Re: Problems with String#hash The offending version is the 1.8.4 version that comes with Ubuntu 6.10, has anyone experienced similar problems? -g. On 11/24/06, Jan Svitok wrote: > On 11/24/06, George Moschovitis wrote: > > Dear devs, > > > > I am facing a very NASTY problem with String#hash > > > > Here is the same code that I run on 3 different computers: > > > > root@kosh:~ # irb > > irb(main):001:0> "User".hash > > => 690465448 > > irb(main):002:0> VERSION > > => "1.8.2" > > > > C:\Documents and Settings\drak>irb > > irb(main):001:0> "User".hash > > => 690465448 > > irb(main):002:0> VERSION > > => "1.8.4" > > > > http://tryruby.hobix.com/ > > Interactive ruby ready. > > >> "User".hash > > => 690465448 > > >> VERSION > > => "1.8" > > > > root@victory:~# irb > > irb(main):001:0> "User".hash > > => -1457018200 > > irb(main):002:0> VERSION > > => "1.8.4" > > > > Please nottice that on the last case I get a different result! Any > > idea why this happens? > > > > thanks in advance for any help! > > > > George. > > string.c:851 > int > rb_str_hash(str) > VALUE str; > { > register long len = RSTRING(str)->len; > register char *p = RSTRING(str)->ptr; > register int key = 0; > > #if defined(HASH_ELFHASH) > register unsigned int g; > > while (len--) { > key = (key << 4) + *p++; > if (g = key & 0xF0000000) > key ^= g >> 24; > key &= ~g; > } > #elif defined(HASH_PERL) > while (len--) { > key += *p++; > key += (key << 10); > key ^= (key >> 6); > } > key += (key << 3); > key ^= (key >> 11); > key += (key << 15); > #else > while (len--) { > key = key*65599 + *p; > p++; > } > key = key + (key>>5); > #endif > return key; > } > > I suspect those #ifdefs. See your config.h what's compiled in. > > -- http://blog.gmosx.com http://nitroproject.org