Referencing nested lists - challenge

Mischa mischa at omnislab.com
Mon Jun 1 16:52:14 EDT 2015


Dear all,

this is some kind of hunt for the best ideas ;)

All of you who've already worked with the JS treelist control should know
this problem. When you need dynamic tree nodes (in other words, want to add
or remove nodes on the fly), you have to deal with a quite nasty construct -
a list that (in principle) can be nested ad infinitum. It consists of 8
columns, where the last column itself is a list that contains a list with 8
columns, where the last column itself is a list that contains ... ok, you
got the picture - these nested lists reflect the nodes, child nodes,
childchild nodes and so on.

OS6 has some new commands to deal with it, however as pointed out in prior
posts they have limitations or simply don't work - so I have to switch to
the hard way - manipulating the treelist construct manually.

So here is the challenge: The $events (evClick, evLoadNode and so on) return
two parameters -  pNodeIdent and pNodeTag. So when you want to add new
children to a node, all you have is its ident. You need to find the list
line for this ident within the  treelist, and calculate its 8th column as
list containing the children. 

My first approach was a recursive search through the treelist for the ident.
This works well, however when the tree is five levels deep, it starts
getting slow. Reeeeeaaaaaal slow.
My second (and current) approach is building a cross reference list with the
ident and a list line reference as row. Such a row would look like

Ident    Reference
19           iTreelist.3.Children.2.Children.6

... and all the code does is to search for the ident in this list and
Calculate [Reference].Children as ChildrenList. During the build of
ChildrenList, the reference table is updated accordingly.
Now, this works fast. Real fast. You add Children to a node 8 levels deep
within the blink of an eye.
However. I love this approach, but it has a big letdown:  You must not
delete nodes from the treelist, because this would destroy the references,
since they refer to list lines. You of course simply could avoid to add a
delete node feature to your treelist implementation, however I like this
problem in an 'academic' way and maybe some of the puzzlers among you like
it, too, or already found a perfect solution for it.

Best greetings and thanks
Mischa

---------------------------------------------------
  T H E   O M N I S   L /\ B     www.omnislab.com
---------------------------------------------------





More information about the omnisdev-en mailing list