On 10/14/07, SpringFlowers AutumnMoon <summercoolness / gmail.com> wrote:
> Gavin Kistner wrote:
>
> > My understanding is that with a directory containing 5,000 MP3s, this
> > solution:
> >
> >   Dir['/share/music/**/*.mp3', '/share/music/*.mp3'].sort_by{ |f|
> >     File.atime(f)
> >   }.reverse[0,10]
> >
> > will call File.atime exactly 5,000 times and create exactly 5,000 Time
> > instances.
>
> won't it call File.atime(f)   (c * n log n)  times?
> n log n is the big O...  O(n log n)... and then c is the constant
> depending on the sort algorithm.

No, sort_by builds a parallel array with the value of each element in
the original collection and uses that array for the sort values.

-- 
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/