View mode: basic / threaded / horizontal-split · Log in · Help
March 13, 2005
tree node mixin template
(ATTN:not tested heavily)

If somebody wants to implement tree alike structure then this (on the clip) 
will help

Beside other features it has three opApply "enumerators":

Node parent = ...;

foreach(Node n; parent.forward) // all children from first to last
foreach(Node n; parent.backward) // all children from last to first
foreach(Node n; parent.deep) // all descendants - children and their 
children

Hope it will be useful.

Andrew Fedoniouk.
http://terrainformatica.com
March 13, 2005
Re: tree node mixin template
In article <d10nld$1e58$1@digitaldaemon.com>, Andrew Fedoniouk says...
>
>(ATTN:not tested heavily)
>
>If somebody wants to implement tree alike structure then this (on the clip) 
>will help
>
>Beside other features it has three opApply "enumerators":
>
>Node parent = ...;
>
>foreach(Node n; parent.forward) // all children from first to last
>foreach(Node n; parent.backward) // all children from last to first
>foreach(Node n; parent.deep) // all descendants - children and their 
>children
>
>Hope it will be useful.

Very nice! I like the nested struct mixin for the custom foreach, too. I think
I'll borrow that idea for MinTL (which currently has the structs at the top
level).
March 14, 2005
Re: tree node mixin template
Yep. That was my initial test drive of mixins.
They are useful indeed.
Assigning names to the "inclusion points" is extremely nice.

"custom foreach" : if I understand Walter idea about structs clearly
then they should work as fast as "plain foreach".

Having defined "forward foreach" I am implicitly defining
visiting order. As far as I can see from D definition
there is no order specified in foreach implementations for
standard collections.

Andrew.


"Ben Hinkle" <Ben_member@pathlink.com> wrote in message 
news:d11rlq$2gss$1@digitaldaemon.com...
> In article <d10nld$1e58$1@digitaldaemon.com>, Andrew Fedoniouk says...
>>
>>(ATTN:not tested heavily)
>>
>>If somebody wants to implement tree alike structure then this (on the 
>>clip)
>>will help
>>
>>Beside other features it has three opApply "enumerators":
>>
>>Node parent = ...;
>>
>>foreach(Node n; parent.forward) // all children from first to last
>>foreach(Node n; parent.backward) // all children from last to first
>>foreach(Node n; parent.deep) // all descendants - children and their
>>children
>>
>>Hope it will be useful.
>
> Very nice! I like the nested struct mixin for the custom foreach, too. I 
> think
> I'll borrow that idea for MinTL (which currently has the structs at the 
> top
> level).
>
>
Top | Discussion index | About this forum | D home