lua-users home
lua-l archive

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


On Sun, Jul 30, 2000 at 09:57:32AM -0300, Luiz Henrique de Figueiredo wrote:
> >Hmm.. I don't know how useful that'll be given that you can't control
> >the order of next() elements...
> 
> Then, why not use
> 	local t={a,b,c}
> 	for i=1 to getn(t) do
> 		-- do something with t[i]
> 	end

Is getn(a_table) O(1) or O(N)?

I'll be much happer with the for loop above that I've been with the
while() loops in the past. I've forgotten the "i=i+1" at the end of a
Lua while loop more times than I care to deal with.

However, the reason I don't like using numeric indexed lists is that
it's costly to insert items or join two lists. It's not that big of a
deal, I end up with most of my linked list data-structures all on the
C++ side anyhow. 

I have found in the past that being able to pass around lists of
items, and iterate over them in order with the simple "for X in LIST"
structure of Python is terribly convinent. I'll have to see how often
I actually care about the order of items in my use of Lua4 stuff.

> >Perhaps you could expose enough about the next() linking behavior
> >of tables to give determinstic ordering.
> 
> How could we do that given that tables are implemented with hash and that
> they're dynamic?

Since you were proposing that I use tables as a replacement for linked
lists, I was assuming that inside of the table data-structure it was
actually linking together hash items into a linked list so that next()
could walk them in that order. I guess that assumption was
incorrect. How does Lua walk a hash table? Is it walking the
hash-space looking for a hit?

-- 
David Jeske (N9LCA) + http://www.chat.net/~jeske/ + jeske@chat.net