digitalmars.D.dtl - tree node mixin template
- Andrew Fedoniouk (145/145) Mar 12 2005 (ATTN:not tested heavily)
- Ben Hinkle (4/14) Mar 13 2005 Very nice! I like the nested struct mixin for the custom foreach, too. I...
- Andrew Fedoniouk (12/36) Mar 13 2005 Yep. That was my initial test drive of mixins.
(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 begin 666 tree.d M=&EV97,-"B\O?"!!=71H;W(Z($%N9')E=R!&961O;FEO=6L 0"!T97)R86EN M;B!T96UP;&%T92 M(&EM<&QE;65T871I;VX-"B\O?"!O9B!T<F5E(&YO9&4- M"B\O? T*=&5M<&QA=&4 =')E95]E;&5M96YT*$Y/1$4I( T*>PT*(" ($Y/ M1$4 7W!A<F5N=#L-"B ("!.3T1%(%]N97AT.PT*(" ($Y/1$4 7W!R978[ M96YT7VEN:71I86QI>F4H*2![(%]N97AT(#T M('1O(&)E('!U8FQI8PT*+R]\( T*=&5M<&QA=&4 =')E95]E;&5M96YT7VUE M9R!O<',-"B ("!.3T1%(&YE>'13:6)L:6YG*"D ('L <F5T=7)N("A?<&%R M9" I/R!N=6QL.B!?;F5X="D[('T-"B ("!.3T1%('!R9793:6)L:6YG*"D M('L <F5T=7)N("A?<&%R96YT(&ES(&YU;&PI/R!N=6QL.B H=&AI<R!I<R!? M<&%R96YT+F9I<G-T0VAI;&0H*3\ ;G5L;#H M12!F:7)S=%-I8FQI;F<H*2![(')E='5R;B!?<&%R96YT(&ES(&YU;&P_(&YU M;&EN9R I("![(')E='5R;B!?<&%R96YT(&ES(&YU;&P_(&YU;&PZ(%]P87)E M;G0N;&%S=$-H:6QD*"D[('T-" T*(" ("\O(&QI;FL =&AI<R!A9G1E<B!. M3T1%("=A9G1E<B<-"B ("!V;VED(&QI;FM!9G1E<BA.3T1%(&%F=&5R*2![ M+E]N97AT*2Y?<')E=B ]('1H:7,[("A?<')E=B ](&%F=&5R*2Y?;F5X=" ] M(" ?0T*(" ("\O(&QI;FL =&AI<R!B969O<F4 3D]$12 G8F5F;W)E)R - M(" (" ('5N;&EN:R I.PT*(" (" (" H7W!R978 /2!B969O<F4N7W!R M978I+E]N97AT(#T =&AI<SL *%]N97AT(#T 8F5F;W)E*2Y?<')E=B ]('1H M:7,[( T*(" (" ("!?<&%R96YT(#T M?0T*(" ("\O('5N;&EN:R!T:&ES(&9R;VT :71S('1R964 (" -"B ("!V M(" ('L-"B (" (" ("!I9B H7VYE>'0 /3T]('1H:7,I("8F("A?<')E M<&%R96YT+E]F:7)S=&-H:6QD(#T ;G5L;#L- M(" (" (" ("!?<&%R96YT+E]F:7)S=&-H:6QD(#T 7W!A<F5N="Y?9FER M<W1C:&EL9"Y?;F5X=#L-"B (" (" ?0T*(" (" ("!?<')E=BY?;F5X M=" ](%]N97AT.R!?;F5X="Y?<')E=B ](%]P<F5V.R!?<&%R96YT(#T ;G5L M;#L M;VP :&%S0VAI;&1R96XH*2![(')E='5R;B!?9FER<W1C:&EL9" A/3T ;G5L M;#L M('T-"B (" -"B (" O+R!A<'!E;F0 ;F5W0VAI;&0 86YD(&UA:V4 :70 M;&%S= T*(" ('9O:60 <'5S:$-H:6QD*"!.3T1%(&YE=T-H:6QD("D-"B M("\O('5N;&EN:R!L87-T(&-H:6QD(&%N9"!R971U<FX :70-"B ("!.3T1% M(" ("\O(&1E=&5R;6EN92!I9B G=&AI<R< :7, 86X 86YC97-T;W( *'!A M(" (" :68H(&X /3T](&YU;&P *0T*(" (" ("!R971U<FX 9F%L<V4[ M(&-O;6UO;B!P87)E;G0 *&EF(&%N>2D ;V8 ='=O(&YO9&5S( T*(" ('-T M871I8R!.3T1%(&-O;6UO;D%N8V5S=&]R*$Y/1$4 =S$L3D]$12!W,BD-"B M9W1H(#T M3D]$12!S=&%C:R Q( T*"0D (&9O<BAW(#T =S$[('< (3T](&YU;&P[('< M=6QL.R!W(#T =RY?<&%R96YT*2!T,B!^/2!W.PT*"0D ('0R+G)E=F5R<V4[ M:#IT M+WP 86-C97-S(&UE=&AO9',O<')O<&5R=&EE<R!L:6ME;'D =&\ 8F4 <'5B M( T*>PT*(" ($Y/1$4 <&%R96YT*"D ("![(')E='5R;B!?<&%R96YT.R!] M=7(-"B\O?"!N;V1E(&)E(")E;G5M<F5T86)L92( =7-I;F< 9F]R96%C: T* M+R]\(&]N07!P;'D +2!W86QK<R!T:')O=6=H(&%L;"!C:&EL9')E; T*+R]\ M12!W.R -"B\O?" ("!F;W)E86-H("A.3T1%('=C.R!W+F9O<G=A<F0I('LN M*&EN="!D96QE9V%T92AI;F]U="!.3T1%*2!D9RD-"B (" ('L (" -"B M92Y?9FER<W1C:&EL9"!I<R!N=6QL*0T*(" (" (" (')E='5R;B!R97-U M9#L M"B (" (" ("!I9B H<F5S=6QT*0EB<F5A:SL-"B (" (" ("!N(#T M;BY?;F5X=#L-"B (" (" ?2!W:&EL92 H("$H;B!I<R!?<&%R96YT7VYO M9&4N7V9I<G-T8VAI;&0I("D-"B (" (" <F5T=7)N(')E<W5L=#L-"B M;W)W87)D5V%L:V5R(&$[(&$N7W!A<F5N=%]N;V1E(#T =&AI<SL <F5T=7)N M(&$[('T-"GT-" T*+R\ =&AE('-A;64 8G5T('=A;&MS(&9R;VT ;&%S="!C M:&EL9"!T;R!F:7)S= T*=&5M<&QA=&4 =')E95]E;&5M96YT7V)A8VMW87)D M96YT7VYO9&4N7V9I<G-T8VAI;&0 :7, ;G5L;"D-"B (" (" ("!R971U M<FX <F5S=6QT.PT*(" (" ("!.3T1%(&X /2!?<&%R96YT7VYO9&4N7V9I M(" (" ?0T*(" ('T-"B ("!"86-K=V%R9%=A;&ME<B!B86-K=V%R9" I M('L 0F%C:W=A<F1786QK97( 83L 82Y?<&%R96YT7VYO9&4 /2!T:&ES.R!R M96YT7V1E97!?;W!!<'!L>2A.3T1%*0T*>PT*(" ("\O('=A;&L =&AR;W5G M:"!A;&P 9&5S8V5N9&%N=', *&-H:6QD<F5N(&%N9"!T:&5I<B!C:&EL9')E M;BD :6X =&AE('1R964-"B ("!P<F]T96-T960 :6YT(&%P<&QY1&5E<"AI M;G0 9&5L96=A=&4H:6YO=70 3D]$12D 9&<I( T*(" ('L ( T*(" (" M*0T*(" (" ("!R971U<FX <F5S=6QT.PT*(" (" 3D]$12!N(#T 7V9I M<G-T8VAI;&0[( T*(" (" 9&\ >PT*"2 (" (')E<W5L=" ](&1G*&XI M(&XN87!P;'E$965P*&1G*3L-"B (" (" :68 *')E<W5L="D 8G)E86L[ M87)E;G1?;F]D93L-"B (" (&EN="!O<$%P<&QY*&EN="!D96QE9V%T92AI M(" ?0T*(" ($1E97!786QK97( 9&5E<" I('L 1&5E<%=A;&ME<B!A.R!A ` end
Mar 12 2005
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).
Mar 13 2005
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).
Mar 13 2005