lua-l archive
[
Date Prev
][
Date Next
][
Thread Prev
][
Thread Next
] [
Date Index
] [
Thread Index
]
Subject
:
fastest way to maintain nested tables of counters?
From
: Tim Menzies <tim@
...
>
Date
: Sun, 15 May 2011 08:48:14 -0400
is the following code the best way to handle auto-initialization of nested table cells to zero?
function inc3(c,x,y,z) -- inc 3d to zero
c[x] = c[x] or {}
c[x][y] = c[x][y] or {}
c[x][y][z] = c[x][y][z] or 0
c[x][y][z] = c[x][y][z] + 1
end
i ask since this task is the core of my naive bayes classifier. so it must be fast.
notes: the table index names won't be known till runtime, so you can auto-init the data with the right names as a pre-processor.
oh- i've read the automagical table entry (
http://lua-users.org/wiki/AutomagicTables
) and i cant quite justify to myself that that approach is preferred to the above.
but i'd like the advice of some Lua gurus!
ADVAthanxNCE
share and enjoy!
:-)
tim menzies
Follow-Ups
:
Re: fastest way to maintain nested tables of counters?
,
Mason Larobina
Re: fastest way to maintain nested tables of counters?
,
Mark Hamburg
Re: fastest way to maintain nested tables of counters?
,
E. Toernig
Prev by Date:
Re: Recursively getting a list of all files executed using dofile
Next by Date:
Re: fastest way to maintain nested tables of counters?
Previous by thread:
Re: Proposal for a new construct in Lua
Next by thread:
Re: fastest way to maintain nested tables of counters?
Index(es):
Date
Thread