Пример #1
0
        private static T _assemble <T>(IEnumerable <Tuple <NodeIndex, T> > dic, Action <T, T> addAction)
        {
            var seq = dic.OrderBy(x => x.Item1, Tree.NodeIndex.GetPostorderComparer());
            var vst = new ElementScroller <Tuple <NodeIndex, T> >(seq);

            foreach (var tr in vst.GetSequence())
            {
                vst.MoveTo(tr)
                .MaybeNext(x => tr.Item1.CurrentDepth > x.Item1.CurrentDepth)
                .TrueOrNot(r => addAction(r.Current.Item2, tr.Item2));
            }
            return(vst.Current.Item2);
        }
Пример #2
0
        private static U convert <T, U>(T self, Func <T, U> generator, Action <U, U> addAction)
            where T : IReadOnlyTreeNode <T>
        {
            if (generator == null)
            {
                throw new ArgumentNullException("generator");
            }
            if (addAction == null)
            {
                throw new ArgumentNullException("addAction");
            }
            var t   = self.Postorder().Select(x => Tuple.Create(x, generator(x)));
            var vst = new ElementScroller <Tuple <T, U> >(t);

            foreach (var tr in vst.GetSequence())
            {
                vst.MoveTo(tr)
                .MaybeNext(x => x.Item1.Children.Contains(tr.Item1))
                .TrueOrNot(r => addAction(r.Current.Item2, tr.Item2));
            }
            return(vst.Current.Item2);
        }