Exemplo n.º 1
0
        public LabeledTree <N, E> TransformTopDown(Func <N, E, N, N> fn)
        {
            var edges = from edge in Edges
                        let newTarget = fn(Label, edge.Label, edge.Target.Label)
                                        select LabeledTree.Edge(edge.Label, LabeledTree.Node(newTarget, edge.Target.Edges).TransformTopDown(fn));

            return(LabeledTree.Node(Label, edges));
        }
Exemplo n.º 2
0
        private LabeledTree <NodeLabel, EdgeLabel> ToTree(Node rootNode, ISet <NodeLabel> visitedNodes,
                                                          Func <NodeLabel, EdgeLabel, NodeLabel, bool> edgeFilter)
        {
            if (visitedNodes.Contains(rootNode.Label))
            {
                return(LabeledTree.Node <NodeLabel, EdgeLabel>(rootNode.Label));
            }
            else
            {
                visitedNodes.Add(rootNode.Label);
                var edges = from e in rootNode.Edges
                            where edgeFilter(rootNode.Label, e.Label, e.TargetLabel)
                            from target in Nodes.FirstOption(n => NodeComparer.Equals(n.Label, e.TargetLabel))
                            select LabeledTree.Edge(e.Label, ToTree(target, visitedNodes, edgeFilter));

                return(LabeledTree.Node(rootNode.Label, edges));
            }
        }