當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Graph.setNode方法代碼示例

本文整理匯總了TypeScript中graphlib.Graph.setNode方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Graph.setNode方法的具體用法?TypeScript Graph.setNode怎麽用?TypeScript Graph.setNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在graphlib.Graph的用法示例。


在下文中一共展示了Graph.setNode方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: 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

示例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:

 jobs.forEach((job : model.BuildSchema) => {
     graph.setNode(job._id, job);
 });
開發者ID:mserranom,項目名稱:lean-ci,代碼行數:3,代碼來源:PipelineGraph.ts


注:本文中的graphlib.Graph.setNode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。