本文整理汇总了TypeScript中graphlib.Graph类的典型用法代码示例。如果您正苦于以下问题:TypeScript Graph类的具体用法?TypeScript Graph怎么用?TypeScript Graph使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Graph类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: fromSchemas
static fromSchemas(dependencies : Array<model.Dependency>, jobs : Array<model.BuildSchema>) : PipelineGraph {
let options = { directed: true, compound: false, multigraph: false };
let graph : Graphlib.Graph<model.BuildSchema, void> = new Graphlib.Graph(options);
jobs.forEach((job : model.BuildSchema) => {
graph.setNode(job._id, job);
});
let jobsByRepo : Map<string, model.BuildSchema> = new Map();
jobs.forEach(job => jobsByRepo.set(job.repo, job));
dependencies.forEach((dependency : model.Dependency) => {
if(jobsByRepo.has(dependency.up) && jobsByRepo.has(dependency.down)) {
graph.setEdge(jobsByRepo.get(dependency.up)._id, jobsByRepo.get(dependency.down)._id);
}
});
if(!Graphlib.alg.isAcyclic(graph)) {
throw new Error('pipeline graph contains circular dependencies:' + JSON.stringify(Graphlib.json.write(graph)));
}
if(graph.sources().length > 1) {
throw new Error('pipeline graph has more than one source nodes: ' + JSON.stringify(Graphlib.json.write(graph)));
}
let pipelineGraph = new PipelineGraph();
pipelineGraph._graph = graph;
pipelineGraph._dependencies = dependencies;
pipelineGraph._builds = jobs;
return pipelineGraph;
}
开发者ID:mserranom,项目名称:lean-ci,代码行数:34,代码来源:PipelineGraph.ts
示例2: addToGraph
private addToGraph(relativePath, inputPath) {
let normalizedPath = this.pathByNamespace(relativePath);
if (this.graph.node(normalizedPath.id)) return;
let mod = new Module({
id: normalizedPath.id,
namespace: normalizedPath.namespace,
relativePath,
inputPath
});
this.graph.setNode(mod.id, mod);
mod.imports.forEach(dep => {
this.graph.setEdge(mod.id, dep);
let normalizedPath = this.pathByNamespace(relativePath);
if (normalizedPath.namespace === this.namespace) {
let inputPath = `${this.srcDir}/${relativePath}.ts`;
let outputPath = `${this.destDir}/${relativePath}.ts`;
this.addToGraph(relativePath, inputPath);
} else {
console.log('EXTERNAL: ' + normalizedPath.path);
}
});
}
开发者ID:chadhietala,项目名称:fs-graph-diff,代码行数:27,代码来源:index.ts
示例3: verifyGraph
private verifyGraph(relativePath: string, inputPath: string) {
let normalizedPath = this.pathByNamespace(relativePath);
let mod = this.graph.node(normalizedPath.id);
let patchImports = mod.calculateImports();
return patchImports.map(patch => {
let operation = patch[0];
let importPath = patch[1];
if (this.graph.node(importPath)) {
if (operation === 'connect') {
this.graph.setEdge(relativePath, importPath);
let inEdges = this.graph.outEdges(importPath);
let inEdgePaths = inEdges.map(edge => this.graph.node(edge.v).inputPath);
return [inputPath, ...inEdgePaths];
} else if (operation === 'disconnect') {
this.graph.removeEdge(normalizedPath.id, importPath);
let inEdges = this.graph.inEdges(importPath);
return null;
}
}
// TODO we need to handle things coming out of node_modules
}).filter(Boolean);
}
开发者ID:chadhietala,项目名称:fs-graph-diff,代码行数:27,代码来源:index.ts
示例4: removeFromGraph
private removeFromGraph(relativePath) {
let normalizedPath = this.pathByNamespace(relativePath);
let id = normalizedPath.id;
let inEdges = this.graph.inEdges(id) || []
let inVertices = inEdges.map(edge => edge.v);
let outEdges = this.graph.outEdges(id) || [];
let outVertices = outEdges.map(edge => edge.w) || [];
if (inVertices.length === 0) {
this.graph.removeNode(id);
outVertices.forEach(node => {
if (this.graph.node(node)) {
this.removeFromGraph(this.graph.node(node).relativePath);
}
});
}
}
开发者ID:chadhietala,项目名称:fs-graph-diff,代码行数:18,代码来源:index.ts
示例5: test_graph
function test_graph() {
var g = new graphlib.Graph();
g.setEdge('a', 'b');
g.setEdge('a', 'b', 1.023);
g.edge('a', 'b');
g.edge({v: 'a', w: 'b'});
graphlib.json.read(graphlib.json.write(g));
graphlib.alg.dijkstra(g, 'a', e => g.edge(e));
graphlib.alg.dijkstraAll(g, e => g.edge(e));
graphlib.alg.dijkstraAll(g);
graphlib.alg.findCycles(g);
graphlib.alg.isAcyclic(g);
graphlib.alg.prim(g, e => g.edge(e));
graphlib.alg.tarjan(g);
graphlib.alg.topsort(g);
}
开发者ID:HawkHouseIntegration,项目名称:DefinitelyTyped,代码行数:20,代码来源:graphlib-tests.ts
示例6:
mod.imports.forEach(dep => {
this.graph.setEdge(mod.id, dep);
let normalizedPath = this.pathByNamespace(relativePath);
if (normalizedPath.namespace === this.namespace) {
let inputPath = `${this.srcDir}/${relativePath}.ts`;
let outputPath = `${this.destDir}/${relativePath}.ts`;
this.addToGraph(relativePath, inputPath);
} else {
console.log('EXTERNAL: ' + normalizedPath.path);
}
});
开发者ID:chadhietala,项目名称:fs-graph-diff,代码行数:12,代码来源:index.ts
示例7: calculatePatch
calculatePatch(entries) {
let nextTree = FSTree.fromEntries(entries);
let currentTree = this.currentTree;
this.currentTree = nextTree;
var patches = currentTree.calculatePatch(nextTree).map(patch => [patch[0], patch[1]]);
patches.forEach(patch => {
let operation = patch[0];
let relativePath = patch[1];
switch(operation) {
case 'change':
this.computeGraph('verify', relativePath);
break;
case 'create':
this.computeGraph('add', relativePath);
break;
case 'unlink':
this.computeGraph('remove', relativePath);
break;
}
});
return this.graph.nodes().map(node => this.graph.node(node).relativePath);
}
开发者ID:chadhietala,项目名称:fs-graph-diff,代码行数:24,代码来源:index.ts
示例8: test_graph
function test_graph() {
var g = new graphlib.Graph({
compound: true,
directed: true,
multigraph: true
});
g.setEdge('a', 'b');
g.setEdge('a', 'b', 1.023, 'test');
g.setEdge({ v: 'a', w: 'b', name: 'test' }, 1.023);
g.hasEdge('a', 'b', 'test');
g.hasEdge({ v: 'a', w: 'b', name: 'test' });
g.removeEdge('a', 'b', 'test');
g.removeEdge({ v: 'a', w: 'b', name: 'test' });
g.edge('a', 'b', 'test');
g.edge({v: 'a', w: 'b', name: 'test'});
g.setDefaultNodeLabel({});
g.setDefaultNodeLabel(() => 42);
g.setDefaultEdgeLabel({});
g.setDefaultEdgeLabel(() => 'e42');
g.setNodes(['a', 'b', 'c'], 42);
g.setParent('d', 'a');
g.parent('d');
g.children('a');
g.filterNodes(v => true);
g.setPath(['a', 'b', 'c'], 42);
graphlib.json.read(graphlib.json.write(g));
graphlib.alg.dijkstra(g, 'a', e => g.edge(e));
graphlib.alg.dijkstraAll(g, e => g.edge(e));
graphlib.alg.dijkstraAll(g);
graphlib.alg.findCycles(g);
graphlib.alg.isAcyclic(g);
graphlib.alg.prim(g, e => g.edge(e));
graphlib.alg.tarjan(g);
graphlib.alg.topsort(g);
graphlib.alg.preorder(g, g.nodes());
graphlib.alg.postorder(g, g.nodes());
}
开发者ID:ArtemZag,项目名称:DefinitelyTyped,代码行数:41,代码来源:graphlib-tests.ts
示例9: generateOrder
export function generateOrder(proj: project.Project) {
const inputGraph = new Graph<FileInput, {}>({ directed: true });
for (const file of proj.files) {
inputGraph.setNode(file.filename, {
file,
groupName: undefined
});
}
for (const file of proj.files) {
for (const dependency of file.dependencies) {
inputGraph.setEdge(file.filename, dependency.filename);
}
}
const acyclicGraph = new Graph<FileGroup, {}>({ directed: true });
for (const group of alg.tarjan(inputGraph)) {
acyclicGraph.setNode(group[0], {
filenames: group
});
for (const member of group) {
inputGraph.node(member).groupName = group[0];
}
}
for (const filename of inputGraph.nodes()) {
const groupName = inputGraph.node(filename).groupName;
for (const edge of inputGraph.inEdges(filename)) {
const otherGroup = inputGraph.node(edge.w).groupName;
if (groupName !== otherGroup) acyclicGraph.setEdge(groupName, otherGroup);
}
}
const order = alg.topsort(acyclicGraph);
let index = 0;
for (const groupName of order) {
const group = acyclicGraph.node(groupName);
const component: file.SourceFile[] = [];
const cyclic = group.filenames.length !== 1;
for (const filename of group.filenames) {
const file = inputGraph.node(filename).file;
if (cyclic) {
file.hasCircularDependencies = true;
file.connectedComponent = component;
component.push(file);
} else {
file.hasCircularDependencies = false;
}
file.orderIndex = index++;
proj.orderFiles.push(file);
}
}
}
开发者ID:daslicht,项目名称:small,代码行数:57,代码来源:order.ts
示例10: if
return patchImports.map(patch => {
let operation = patch[0];
let importPath = patch[1];
if (this.graph.node(importPath)) {
if (operation === 'connect') {
this.graph.setEdge(relativePath, importPath);
let inEdges = this.graph.outEdges(importPath);
let inEdgePaths = inEdges.map(edge => this.graph.node(edge.v).inputPath);
return [inputPath, ...inEdgePaths];
} else if (operation === 'disconnect') {
this.graph.removeEdge(normalizedPath.id, importPath);
let inEdges = this.graph.inEdges(importPath);
return null;
}
}
// TODO we need to handle things coming out of node_modules
}).filter(Boolean);
开发者ID:chadhietala,项目名称:fs-graph-diff,代码行数:21,代码来源:index.ts
注:本文中的graphlib.Graph类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论