lua-users home
lua-l archive

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


On Thu, Sep 5, 2013 at 6:53 PM, Steve Litt <slitt@troubleshooters.com> wrote:
> 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.

Yep, basically turn your array into a set:

http://stevedonovan.github.io/Penlight/api/modules/pl.tablex.html#index_map

No longer O(N), but O(log N)

So we'll get the entertaining (but _not_ paradoxical) fact that a good
algorithm in Lua can beat a bad algorithm in C, for sufficiently large
N