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, 2020 at 1:05 PM Raul Miller <rauldmil...@gmail.com> wrote:
>
> 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.
>     node=. y
>   end.
>   (<node) ({.x)} len{.m,a:
> )
>
>    leaves =. 'g';1
>    paths =. (,0);1 0
>    tree =. paths mktree leaves
>    tree -: 'g';<,<1
> 1
>
> That's not quite the same as your original specification, but I can't
> see any good reason to require that non-leaf nodes of the tree be rank
> zero.
>
> Also, this isn't going to be all that efficient -- but (if this is
> what you are looking for) there are some minor improvements available.
>
> Thanks,
>
> --
> Raul
>
> On Sat, Sep 19, 2020 at 11:51 AM Raoul Schorer <raoul.scho...@gmail.com> 
> wrote:
> >
> > Dear all,
> >
> > I am attempting to recover trees from a varying length path encoding. 
> > Chapter
> > 32: Trees <https://www.jsoftware.com/help/learning/32.htm> 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
> > paths =. (,0);1 0
> > tree =. paths mktree leaves
> > tree -: 'g';<<1
> > 1
> >
> > What would be the definition of 'mktree'? Is there a "common idiom" APL
> > solution to that?
> >
> > Thanks a bunch,
> > Raoul
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to