Roman Tsisyk
2014-09-03 17:30:54 UTC
Hi!
I wonder why #table (length operator for table) is not O(1).
```
MSize LJ_FASTCALL lj_tab_len(GCtab *t)
{
MSize j = (MSize)t->asize;
if (j > 1 && tvisnil(arrayslot(t, j-1))) {
MSize i = 1;
while (j - i > 1) {
MSize m = (i+j)/2;
if (tvisnil(arrayslot(t, m-1))) j = m; else i = m;
}
return i-1;
}
if (j) j--;
if (t->hmask <= 0)
return j;
return unbound_search(t, j);
}
```
How am I supposed to work with Lua after that?
I wonder why #table (length operator for table) is not O(1).
```
MSize LJ_FASTCALL lj_tab_len(GCtab *t)
{
MSize j = (MSize)t->asize;
if (j > 1 && tvisnil(arrayslot(t, j-1))) {
MSize i = 1;
while (j - i > 1) {
MSize m = (i+j)/2;
if (tvisnil(arrayslot(t, m-1))) j = m; else i = m;
}
return i-1;
}
if (j) j--;
if (t->hmask <= 0)
return j;
return unbound_search(t, j);
}
```
How am I supposed to work with Lua after that?
--
WBR,
Roman Tsisyk <roman-***@public.gmane.org>
http://tarantool.org/ - an efficient in-memory data store and a Lua
application server
http://try.tarantool.org/ - try your Lua code **online**
WBR,
Roman Tsisyk <roman-***@public.gmane.org>
http://tarantool.org/ - an efficient in-memory data store and a Lua
application server
http://try.tarantool.org/ - try your Lua code **online**