From: SpringFlowers AutumnMoon Date: 2007-09-18T18:30:18+09:00 Subject: Re: how to use tuple as hash key Stefano Crocco wrote: > > insert the line > > h2.rehash > > after > > h2[a] = "ha" > > you'll get the expected behaviour. actually if the code is for i in 1..2 for j in 1..2 a[0] = i a[1] = j h2[a] = "ha" h2.rehash end end p h2 it will print out: {[2, 2]=>"ha"} ========================= if i use h2 = {} a = [0, 0] for i in 1..2 for j in 1..2 a[0] = i a[1] = j h2[a.dup] = "ha" end end p h2 then it will print out {[1, 2]=>"ha", [2, 1]=>"ha", [1, 1]=>"ha", [2, 2]=>"ha"} but my question is, if i run the loop 10 million times (for some statistics), then it will actually duplicate the array 10 million times, which is memory hungry. so i wonder what is a better way. if a is just a list of numbers, i can certainly use a.join(",") as the key... but looping 10 million times will also create "frozen strings" in the hash table 10 million times too? -- Posted via http://www.ruby-forum.com/.