lua-users home
lua-l archive

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


On Monday 29 May 2006 20:57, Jose Marin wrote:
> One part of the code checks all elements on an array
> against each other.
>
> Is there some optimized way of do this in Lua?

Assuming I understood correctly and that you have lots of elements, a faster 
way that avoids the nested loop could be:
- create a table using elements as keys and their indexes as values.
- scan the elements and check if they are in the table.

Sorry for not writing actual Lua code, but it's some time I don't write any 
and I don't want to make too many syntax mistakes :-)

Step 1 will be a little more complex if you need to enumerate multiple 
conflicts with the same element in step 2 (for example, the key could be a 
table including both an element and its index).

  Enrico