From: Bob Hutchison Date: 2007-10-24T00:36:38+09:00 Subject: Re: pop/push, shift/unshift On 23-Oct-07, at 11:17 AM, Bob Hutchison wrote: > > On 23-Oct-07, at 10:52 AM, Jesús Gabriel y Galán wrote: >> >> I understand your explanation, but this sounds like a bug to me. I >> understand the optimization part of not shifting everything in the >> shift method, but if that's a desired way of working I suppose it >> should be warned for the users of Array. In light of this then, the >> recommended approach for queue semantics would be to use unshift and >> pop? >> > > I just did a quick test. It looks as though Ruby is now handling > both the unshift/pop and push/shift properly. I know when I > reported it in Ruby 1.8.4 there was a discussion about how to deal > with this, and it looks as though 1.8.5 has it working (or I've > patched my version of Ruby and have forgotten about it). > > So maybe not a problem, or too big of a problem. Just don't forget > about the cells holding references, that is definitely there in 1.8.5. I just wrote a little test script. It looks as though push will cleanup the empty space left by shift. So your queue should be okay on *average* either way you implement it. Though you'll be growing the array until push is called (and at the same time there will be invisible references to objects)... generally working but with potentially subtle bugginess. Cheers, Bob > > Cheers, > Bob > >> Thanks, >> >> Jesus. >> > > ---- > Bob Hutchison -- tumblelog at http:// > www.recursive.ca/so/ > Recursive Design Inc. -- weblog at http://www.recursive.ca/ > hutch > http://www.recursive.ca/ -- works on http:// > www.raconteur.info/cms-for-static-content/home/ > > > > ---- Bob Hutchison -- tumblelog at http:// www.recursive.ca/so/ Recursive Design Inc. -- weblog at http://www.recursive.ca/ hutch http://www.recursive.ca/ -- works on http://www.raconteur.info/ cms-for-static-content/home/