Walking Trees Backwards

David Bovill david at architex.tv
Thu Sep 11 14:51:31 CDT 2008


Yes - thanks that's what I was thinking.... it does not work though as while
the maximum depth are all leaves of a tree structure there are other leaves
lower down the branches. So I think I'll have to use a technique I've done
before which is to turn the tree into an index of paths. So in your example:

task1
>    task1.a
>    task1.b
>        task1.b.1
> task2
>    task2.a
>        task2.a.1
>    task2.b
>    task2.c
> task3


becomes

task1
task1/task1.a
task1/task1.b
task1/task1.b/task1.b.1
task2
task2/task2.a
task2/task2.a/task2.a.1
task2/task2.b
task2/task2.c
task3

No each line is a leaf, and yu can do what you want to the index, as it is
easy to reconstruct the outline from the paths (order does not matter). Now
the "problem" with the new arrays":

What I really want to do with a line like "task1/task1.b/task1.b.1" is stuff
like:

put ""task1.b"" into outlineArray ["task1"]
put "task1.b.1" into outlineArray ["task1"]["task1.b"]

Things like:

put keys(outlineArray ["task1"])  => task1.b

Seem to work fine. And you can use vaiable keys - so:

put "task1" into someKey
> put "task1.b.1" into outlineArray [someKey] ["task1.b"]
> put keys(outlineArray)  => task1


Yet to be able to write a recursive function I need to be able to do this
without knowing how deep I am in the recursion: I'm going to try doing that
by defining a function to put a value into an array. I can't see how thats
possible right now without "do" in which case I would give up and keep using
XML as it will be faster.



More information about the use-livecode mailing list