[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: I miss table.foreach
- From: Steve Litt <slitt@...>
- Date: Thu, 5 Sep 2013 12:53:52 -0400
On Thu, 5 Sep 2013 08:52:47 +0200
David Demelier <demelier.david@gmail.com> wrote:
> For me, I personally miss more something like table.find (which never
> existed). A kind of function like that would be great :-), there's
> also table.sort so table.find could be a great improvement.
>
> Cheers,
You could easily write your own table.find that iterates through all
items til it finds a value that matches the argument. But it would be
slow with big tables.
More practical might be to have an index table whose keys are the value
or value part in question, and whose values are the key of the original
table. Then you write your table.find something like
orgtable[indextable["searchkey"]]
You'd probably put an add metamethod on orgtable to write the correct
entry to indextable.
I'm not a Comp Sci expert, but I'd imagine this would continue to have
fast lookups, on a one by one basis, even if you had 10K items in the
lists.
Thanks,
SteveT
Steve Litt * http://www.troubleshooters.com/
Troubleshooting Training * Human Performance