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?
* unconfuse the confusing.
unconfuse the confusing.
FH V.6.2.7 Win 10 64 bit
- tatewise
- Megastar
- Posts: 28341
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: unconfuse the confusing.
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
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
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
Re: unconfuse the confusing.
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.
Thanks, I actually think I can code that, without spending weeks on it.
FH V.6.2.7 Win 10 64 bit