* unconfuse the confusing.

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
User avatar
Ron Melby
Megastar
Posts: 917
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

unconfuse the confusing.

Post 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?
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28341
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: unconfuse the confusing.

Post 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
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 917
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: unconfuse the confusing.

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