|
Actually, insert and remove appear to use a binary search, so the time
would be logarithmic, not linear.
http://www.lua.org/source/5.3/ltable.c.html#luaH_getn
Called from:
http://www.lua.org/source/5.3/lvm.c.html#luaV_objlen
http://www.lua.org/source/5.3/lapi.c.html#lua_len
http://www.lua.org/source/5.3/lauxlib.c.html#luaL_len
http://www.lua.org/source/5.3/ltablib.c.html#aux_getn
http://www.lua.org/source/5.3/ltablib.c.html#tinsert
I’m pretty sure insert/remove do NOT take linear time, though the time is complex to compute since Lua may or may not have migrated the array to the “array part” of the table. In either case your insert/remove time will be much closer to O(1) than O(n) since the table is based on hashing.