lua-users home
lua-l archive

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

On 16-08-20 03:34 AM, Soni L. wrote:
> Each C API function
> should handle length on its own way.


1. Will "table.insert(t, el)" and "t[#t+ 1] = el" remain equivalent?
2. Can you offer length algorithm that is O(1). Id est consumes constant
time to determine sequence length of table?

2.1 Because something like

local len = 1
while (t[len] ~= nil) do
  len = len + 1
return len

is O(n) and behaves like C's strlen().

I'm getting tired or assertions that Lua "should" something. It's not.