[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Closest hash value



John Porter wrote:
> 
> Fergal wrote:
> > John Porter wrote:
> > >
> > > Chaim wrote:
> > > > >>>>> "FD" == Fergal Daly <fergal@esatclear.ie> writes:
> > > >
> > > > FD> You can get the "first" key with
> > > > FD> ($best) = each %h;
> > > >
> > > > I know, but I'm not sure if that is optimized. It may cause all
> > > > 1_000_000 keys to be copied to the stack and then the first item
> > > > removed.
> > > >
> > > > Anyone know for sure?
> > >
> > > Sure!  No lists.  each() is absolutely O(1).
> > >
> >
> > Unless it's a weird tied hash in which case anything goes,
> 
> Oh, yeah, true.  But even then it only calls FIRSTKEY (or NEXTKEY), once
> per each, rather than, as Chaim feared, calling FIRSTKEY/NEXTKEY to get
> a list of all the keys.

I think my first tied hash called keys() as part of FIRSTKEY (this was
before I had any sort of clue) that's what made me think of it to start
with,

Fergal

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe