Page 1 of 1

unconfuse the confusing.

Posted: 15 May 2019 20:48
by Ron Melby
please dont rattle on about associative arrays, which have no guaranteed ordering...
I understand the tables are presently keyed by arrival order.

I have tables ahnentafel, indiPTR, generation, their keys are obviously 1..n but the values are not in "order" (that being the order I WANT)
so reading up on this is so confusing. can I use table.sort, ordered by value, and will that also reorder the key by rrn.

that is lets say now, I have
key 1 val 3
key 2 val 2
key 3 val 1
in my index table ahnentafel
at end, I want
key 1 val 1
key 2 val 2
key 3 val 3

or do I have to put them in new tables

i = 1
caught = 0
for _, val in pairs(anhentafel) do
for k = 1 to (caught= #t) do
if k = val
tblahnen = ahnentafel [val]
tblindi[i} = indiPTR[key]
tblGEN = generation[key]
i = i + 1
caught = caught + 1
end
end
I know I am not correct in the wrong ender quite, but I can figure that out.
or is there even slicker ways to do this for a index table and associated arrays?

Re: unconfuse the confusing.

Posted: 15 May 2019 21:42
by tatewise
The easiest solution is to have one table holding the three values, and sort that one table on the ahnentafel values.
So, instead of:

table.insert(ahnentafel, at)
table.insert(generation, gen)
table.insert(ancestors, ptrHUSB:Clone())

you use:

table.insert( tblData, { ahnentafel=at; generation=gen; ancestors=ptrHUSB:Clone(); } )

then to sort into ahnentafel order you use:

table.sort( tblData, function(a,b) return a.ahnentafel < b.ahnentafel end )

To split out into three tables use:

local ahnentafel = {}
local generation = {}
local ancestors = {}
for i, j in ipairs (tblData) do
table.insert(ahnentafel, j.ahnentafel)
table.insert(generation, j.generation)
table.insert(ancestors, j.ancestors:Clone())
end

Re: unconfuse the confusing.

Posted: 16 May 2019 00:20
by Ron Melby
Yes, it didnt look like a one step process, but it is worth doing, because of down the road programming simplicity. I thought it would go something like that, if you remember my cemetery list, where I was getting cemetery in one table, address and interments in another, and cutting them all out in order thats about what we (you helping and doing the coding) did. I was looking for a fuhrerprinzip magic thing, but it takes a couple magics to make it happen.

Thanks, I actually think I can code that, without spending weeks on it.