Hash value of { n => n }

e$B1sF#$H?=$7$^$9e(B

1.9 e$B$G0J2<$N%3!<%I$r<B9T$9$k$H!"$+$J$j;~4V$,$+$+$j$^$9!#e(B

$ time ./ruby -ve ‘h = {}; 10000.times {|x| h[{ x => x }] = 1 }’
ruby 1.9.0 (2007-09-15 patchlevel 0) [i686-linux]

real 0m12.369s
user 0m9.050s
sys 0m3.280s

e$BG$0U$Ne(B x e$B$K$D$$$Fe(B { x => x } e$B$N%O%C%7%eCM$,$9$Y$Fe(B 1
e$B$G$"$k$?$a!“e(B
e$B>WFM$7$^$/$C$F$$$k$h$&$G$9!#e(B
e$BBQ>[email protected]$O$=$l$[$I=EMW$8$c$J$$$+$b$7$l$^$;$s$,!”$A$g$C$H4JC1$Ke(B
e$B>WFM$7$9$.$J5$$b$7$^$9!#$I$&$G$7$g$&$+!#e(B

e$B>e$N%3!<%I$K$D$$$F$O0J2<$N%Q%C%A$G$H$j$"$($:2r7h$7$^$9!#e(B

Index: hash.c

— hash.c (revision 13472)
+++ hash.c (working copy)
@@ -1461,6 +1461,7 @@
{
if (key == Qundef) return ST_CONTINUE;
*hval ^= rb_hash(key);

  • *hval *= 137;
    *hval ^= rb_hash(val);
    return ST_CONTINUE;
    }

$ time ./ruby -ve ‘h = {}; 10000.times {|x| h[{ x => x }] = 1 }’
ruby 1.9.0 (2007-09-15 patchlevel 0) [i686-linux]

real 0m0.182s
user 0m0.030s
sys 0m0.150s

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs