public WhenNoDependencies() { _graph = new DependencyGraph <string>(); _graph.AddNode("c"); _graph.AddNode("a"); _graph.AddNode("b"); }
public WithSingleDependencyChain() { _graph = new DependencyGraph <string>(); _graph.AddNode("3"); _graph.AddNode("0"); _graph.AddNode("1"); _graph.AddNode("2"); _graph.Connect("3", "1"); _graph.Connect("3", "2"); _graph.Connect("2", "1"); _graph.Connect("1", "0"); }
private IEnumerable <string> GetFromQueries(IEnumerable <NamedClause> namedFroms, IEnumerable <IClause> plainFroms, IEnumerable <IClause> wheres) { var graph = new DependencyGraph <string>(); var loadedClauses = namedFroms.ToDictionary(f => f.QueryName, f => f.Query); foreach (var from in namedFroms) { if (!graph.HasNode(from.QueryName)) { graph.AddNode(from.QueryName); } BuildDepGraph(graph, loadedClauses, from, from.QueryName, true); } foreach (var from in plainFroms) { BuildDepGraph(graph, loadedClauses, from, string.Empty, true, true); } foreach (var where in wheres) { BuildDepGraph(graph, loadedClauses, where, string.Empty, true, true); } return(graph.TopologicalSort().Select(queryName => loadedClauses[queryName])); }
private IDependencyGraph <BranchInfo> CreateBranchGraph(Configuration config) { var branchesByName = config.Branches.ToDictionary(x => x.Name); var graph = new DependencyGraph <BranchInfo>(); foreach (var branchInfo in config.Branches) { if (branchInfo.Parent != null) { var source = branchesByName[branchInfo.Parent]; var target = branchesByName[branchInfo.Name]; graph.AddDependency(source, target); } else { graph.AddNode(branchesByName[branchInfo.Name]); } } return(graph); }
private IDependencyGraph<BranchInfo> CreateBranchGraph(Configuration config) { var branchesByName = config.Branches.ToDictionary(x => x.Name); var graph = new DependencyGraph<BranchInfo>(); foreach (var branchInfo in config.Branches) { if (branchInfo.Parent != null) { var source = branchesByName[branchInfo.Parent]; var target = branchesByName[branchInfo.Name]; graph.AddDependency(source, target); } else { graph.AddNode(branchesByName[branchInfo.Name]); } } return graph; }
private void BuildDepGraph(DependencyGraph <string> graph, Dictionary <string, string> loadedClauses, IClause clause, string queryName, bool unCheckHasNode, bool notSetToNode = false) { if (unCheckHasNode || !graph.HasNode(queryName)) { foreach (var depend in this.Factory.GetDependNames(clause.Query)) { if (!loadedClauses.ContainsKey(depend)) { var newClause = new NamedClause(this.Factory, depend); loadedClauses.Add(newClause.QueryName, newClause.Query); BuildDepGraph(graph, loadedClauses, newClause, newClause.QueryName, false); } if (notSetToNode) { graph.AddNode(depend); } else { graph.AddEdge(depend, queryName); } } } }
private static void EmitStructures() { StreamWriter file = GetOutputFile("types"); // build dependency graph DependencyGraph dg = new DependencyGraph(); foreach (Peer peer in peer_map.Peers) { dg.AddNode(peer); // peer depends on nearest base if (peer.NearestBase != null) { dg.AddEdge(peer.NearestBase, peer); } // peer depends on any value types used for fields foreach (PeerField field in peer.Fields) { if (field.Peer.IsValueType) { dg.AddEdge(field.Peer, peer); } } } // write structures in order foreach (Peer peer in dg.TopologicalSort()) { if (peer.IsOpaque) { continue; } if (peer.IsEnum) { file.WriteLine("typedef {0} {1};", peer.UnderlyingPeer.Name, peer.Name); file.WriteLine("enum _{0} {{", peer.Name); ArrayList enum_lines = new ArrayList(); foreach (string name in peer.EnumConstants.Keys) { enum_lines.Add(String.Format("\t{0}_{1} = {2}", peer.Name, name, peer.EnumConstants[name] )); } file.WriteLine("{0}\n}};\n", Join(",\n", enum_lines)); } else { file.WriteLine("typedef struct _{0} {{", peer.Name); // base type if (peer.NearestBase != null) { file.WriteLine("\t{0} __base;", peer.NearestBase.Name); file.WriteLine(); } // fields foreach (PeerField field in peer.Fields) { bool use_struct = true; if (field.Peer.IsValueType || field.Peer.IsOpaque) { use_struct = false; } file.WriteLine("\t{0}{1}{2};", use_struct ? "struct _" : "", field.Peer.GetTypedef(field.Peer.IsValueType ? 0 : 1), field.Name ); } file.WriteLine("}} {0};\n", peer.Name); } } }
private static void EmitStructures () { StreamWriter file = GetOutputFile ("types"); // build dependency graph DependencyGraph dg = new DependencyGraph (); foreach (Peer peer in peer_map.Peers) { dg.AddNode (peer); // peer depends on nearest base if (peer.NearestBase != null) dg.AddEdge (peer.NearestBase, peer); // peer depends on any value types used for fields foreach (PeerField field in peer.Fields) { if (field.Peer.IsValueType) dg.AddEdge (field.Peer, peer); } } // write structures in order foreach (Peer peer in dg.TopologicalSort ()) { if (peer.IsOpaque) continue; if (peer.IsEnum) { file.WriteLine ("typedef {0} {1};", peer.UnderlyingPeer.Name, peer.Name); file.WriteLine ("enum _{0} {{", peer.Name); ArrayList enum_lines = new ArrayList (); foreach (string name in peer.EnumConstants.Keys) { enum_lines.Add (String.Format ("\t{0}_{1} = {2}", peer.Name, name, peer.EnumConstants[name] )); } file.WriteLine ("{0}\n}};\n", Join (",\n", enum_lines)); } else { file.WriteLine ("typedef struct _{0} {{", peer.Name); // base type if (peer.NearestBase != null) { file.WriteLine ("\t{0} __base;", peer.NearestBase.Name); file.WriteLine (); } // fields foreach (PeerField field in peer.Fields) { bool use_struct = true; if (field.Peer.IsValueType || field.Peer.IsOpaque) use_struct = false; file.WriteLine ("\t{0}{1}{2};", use_struct ? "struct _" : "", field.Peer.GetTypedef (field.Peer.IsValueType ? 0 : 1), field.Name ); } file.WriteLine ("}} {0};\n", peer.Name); } } }