*unconfuse the confusing.

Writing and using plugins for Version 5 and above.
User avatar
Ron Melby
Posts: 337
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

unconfuse the confusing.

Postby Ron Melby » 15 May 2019 20:48

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[i] = ahnentafel [val]
tblindi[i} = indiPTR[key]
tblGEN[i] = generation[key]
i = i + 1
caught = caught + 1
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?
FH V.6.2.7 Win 7 64 bit

User avatar
Posts: 16015
Joined: 25 May 2010 11:00
Family Historian: V6.2
Location: Torbay, Devon, UK

Re: unconfuse the confusing.

Postby tatewise » 15 May 2019 21:42

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())
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
Ron Melby
Posts: 337
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: unconfuse the confusing.

Postby Ron Melby » 16 May 2019 00:20

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.
FH V.6.2.7 Win 7 64 bit

Return to “Plugin Discussions”

Who is online

Users browsing this forum: Jane and 2 guests