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


TypeScript Graph.sources方法代碼示例

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


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


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