• Subject: Re: Lua 5.2 Length Operator and tables (bug?)
• From: Dirk Laurie <dirk.laurie@...>
• Date: Tue, 17 Apr 2012 18:48:56 +0200

```> I think the main problem is that you cannot "see" from the value of #t is a proper sequence or not, or if there is a proper subsequence. #t always returns a "valid looking" result even if the table is not valid table and the value is basically meaningless. To me that is the problem.

Calculating #t by the current algorithm takes O(log(count)) time.

Finding out whether a table is a proper sequence is a nontrivial
problem that can be solved only by something equivalent to the
following method:

Go through the entire table, counting positive integer keys and
keeping track of the      highest integer key.  If these numbers are
the same at the end, it is a proper sequence.

That method takes O(count) time.  If you are in a position where
someone you can't trust modified your table and you need to know
whether it is still a proper sequence, you must do just that.

It is totally unreasonable to want slow down #t for everybody.

```