Re: [Jprogramming] varying path length relation to tree

2020-09-21 Thread Raul Miller
This is approximately the ideal way of generating the tree, as long as all paths which are present in the tree are listed. (If leaves with empty values were not listed, this approach would delete them from the tree. That's probably fine, but it's worth documenting.) That said, note also that this

Re: [Jprogramming] varying path length relation to tree

2020-09-20 Thread xash
This is much simpler; groups based on the first element, recursively call itself until no path is left, and links the result back together. Well, was at least a nice exercise with L:n yesterday. :-) ] leaves =. 'g';1 ] paths =. (,0);1 0 group =: {.&>@[ )@[ $:&.> group)@.(0<#@;@[) pat

Re: [Jprogramming] varying path length relation to tree

2020-09-19 Thread xash
Using L: to apply /. on each leaf (splitting paths) until finished, then rebuilding the paths via {:: and using them to index into the elements. ] leaves =. 'g';1 ] paths =. (,0);1 0 NB. tree based on paths with <'' as elements: structure=: ({.@> )^:(*@#@;)L:1^:_ NB. <'' -> path ->

Re: [Jprogramming] varying path length relation to tree

2020-09-19 Thread Raoul Schorer
Thanks Raul, your code helped me a lot to clarify my interpretation of the problem! I ended up using a recursive verb applying paths #~ -. pathb modl =. k&( paths nextp ;< nextl ) > L: 1 {: mktree^:_ paths; L: 1 {: mktree^:_ paths; wrote: > I should have said: this isn't going to be all that

Re: [Jprogramming] varying path length relation to tree

2020-09-19 Thread Raul Miller
I should have said: this isn't going to be all that efficient on large data structures. Efficiency on small data structures tends to be trivial (which has tended to yield lots of potentially misleading concepts and claims about efficiency in the popular press), Thanks, -- Raul On Sat, Sep 19,

Re: [Jprogramming] varying path length relation to tree

2020-09-19 Thread Raul Miller
Hmm... Would something like this fit what you are looking for? mktree=:1 :0 (0#a:) m mktree y : for_p. m do. path=.;p [ leaf=.p_index{::y x=.path x insertnode leaf end.x ) insertnode=:1 :0 : len=. (#m)>.1+ndx=. {.x if.1<#x do. node=. (}.x) (ndx{::len{.m) insertnode y else.

[Jprogramming] varying path length relation to tree

2020-09-19 Thread Raoul Schorer
Dear all, I am attempting to recover trees from a varying length path encoding. Chapter 32: Trees shows how to do it for fixed-length paths, but I wasn't able to find a suitable solution to the varying length case. To illustrate: leaves =. 'g';1 pa