fields and elements

classic Classic list List threaded Threaded
3 messages Options
s
Reply | Threaded
Open this post in threaded view
|

fields and elements

s
Newbie level
------------
I would appreciate some clarification on a query I have.

In lua tables, fields (with string-indices) are accessed in
constant time.

What about the elements of an array (using tables of course)?
Constant time or linear?

-- this question came up while reading a part of the lua book.

Thanks.

SNS

Reply | Threaded
Open this post in threaded view
|

Re: fields and elements

Luiz Henrique de Figueiredo
>In lua tables, fields (with string-indices) are accessed in
>constant time.
>
>What about the elements of an array (using tables of course)?
>Constant time or linear?

If by array you mean a table indexed with integers, then yes, it's constant
time. Table accesses are done in constant time no matter what type of index.
--lhf

s
Reply | Threaded
Open this post in threaded view
|

Re: fields and elements

s
At 10:41 06/01/01 -0200, lhf kindly replied:

>If by array you mean a table indexed with integers, then yes, it's constant
>time. Table accesses are done in constant time no matter what type of index.
>--lhf

Many thanks.
--sns