How to use the toposort function in toposort

To help you get started, we’ve selected a few toposort examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github neo-one-suite / neo-one / packages / neo-one-server / src / PluginManager.ts View on Github external
public async registerPlugins(pluginNames: readonly string[]): Promise {
    const plugins = pluginNames.map((pluginName) =>
      pluginsUtil.getPlugin({
        logger: this.logger,
        pluginName,
      }),
    );

    const graph = plugins.reduce>(
      (acc, plugin) => acc.concat(plugin.dependencies.map<[string, string]>((dep) => [plugin.name, dep])),
      [],
    );

    const sorted = _.reverse(toposort(graph));
    const pluginNameToPlugin = plugins.reduce<{ [pluginName: string]: Plugin }>(
      (acc, plugin) => ({
        ...acc,
        [plugin.name]: plugin,
      }),
      {},
    );
    const noDepPlugins = plugins.filter((plugin) => plugin.dependencies.length === 0);

    await Promise.all(noDepPlugins.map(async (plugin) => this.registerPlugin(plugin)));

    // tslint:disable-next-line no-loop-statement
    for (const pluginName of sorted) {
      const plugin = pluginNameToPlugin[pluginName] as Plugin | undefined;
      // The later plugins will fail with missing dependency
      if (plugin !== undefined) {
github OpenZeppelin / openzeppelin-sdk / packages / cli / src / models / network / NetworkController.ts View on Github external
private _getAllSolidityLibNames(contractNames: string[]): string[] {
    const graph: string[][] = [];
    const nodes: string[] = [];

    contractNames.forEach(contractName => {
      this._populateDependencyGraph(contractName, nodes, graph);
    });

    // exclude original contracts
    return [...difference(toposort(graph), contractNames).reverse()];
  }
github neo-one-suite / neo-one / packages / neo-one-server / src / PluginManager.js View on Github external
async registerPlugins(pluginNames: Array): Promise {
    const plugins = pluginNames.map((pluginName) =>
      pluginsUtil.getPlugin({
        monitor: this._monitor,
        pluginName,
      }),
    );
    const graph = plugins.reduce(
      (acc, plugin) =>
        acc.concat(plugin.dependencies.map((dep) => [plugin.name, dep])),
      [],
    );

    const sorted = toposort(graph).reverse();
    const pluginNameToPlugin = plugins.reduce((acc, plugin) => {
      acc[plugin.name] = plugin;
      return acc;
    }, {});
    const noDepPlugins = plugins.filter(
      (plugin) => plugin.dependencies.length === 0,
    );
    await Promise.all(
      noDepPlugins.map((plugin) => this._registerPlugin(plugin)),
    );
    for (const pluginName of sorted) {
      const plugin = pluginNameToPlugin[pluginName];
      // The later plugins will fail with missing dependency
      if (plugin != null) {
        // eslint-disable-next-line
        await this._registerPlugin(pluginNameToPlugin[pluginName]);
github steelbrain / pundle / packages / pundle-dev-middleware / src / client / hmr-client.js View on Github external
nodes.push([moduleId, null])
    if (hmrAccepted === 'direct') return

    const { parents } = oldModules[moduleId]
    parents.forEach(parent => {
      nodes.push([moduleId, parent])
      iterate(parent)
    })
  }
  moduleIds.forEach(iterate)
  if (rejected) {
    throw new Error(`HMR not applied because some modules rejected/did not accept it`)
  }

  // Remove null at the end
  return toposort(nodes).slice(0, -1)
}
github ChristopherChudzicki / math3d-react / client / src / utils / mathParsing / mathscope.js View on Github external
symbols: Symbols,
  childMap: ChildMap,
  onlyTheseAndChildren: ?(Set | Array) = null
): {
  evalOrder: Array,
  cycles: { [nodeName: string]: Array }
} {
  // construct dependency graph as array of nodes
  const nodesToInclude = onlyTheseAndChildren
    ? [...getDescendants(onlyTheseAndChildren, childMap)]
    : Object.keys(childMap)

  let sorted, isolated, edges, cycles, withoutCycles
  try {
    ( { edges, isolated } = getSubgraphEdges(childMap, nodesToInclude))
    sorted = toposort(edges)
    cycles = {}
  }
  catch (error) {
    if (error.message.startsWith('Cyclic dependency')) {
      ( { withoutCycles, cycles } = removeCycles(childMap));
      ( { edges, isolated } = getSubgraphEdges(withoutCycles,
        nodesToInclude.filter(node => !cycles.hasOwnProperty(node))
      ))
      sorted = toposort(edges)
    }
    else {
      throw error
    }
  }

  const evalOrder = [...sorted, ...isolated]
github ChristopherChudzicki / math3d-react / client / src / utils / mathParsing / mathscope.js View on Github external
? [...getDescendants(onlyTheseAndChildren, childMap)]
    : Object.keys(childMap)

  let sorted, isolated, edges, cycles, withoutCycles
  try {
    ( { edges, isolated } = getSubgraphEdges(childMap, nodesToInclude))
    sorted = toposort(edges)
    cycles = {}
  }
  catch (error) {
    if (error.message.startsWith('Cyclic dependency')) {
      ( { withoutCycles, cycles } = removeCycles(childMap));
      ( { edges, isolated } = getSubgraphEdges(withoutCycles,
        nodesToInclude.filter(node => !cycles.hasOwnProperty(node))
      ))
      sorted = toposort(edges)
    }
    else {
      throw error
    }
  }

  const evalOrder = [...sorted, ...isolated]

  return { evalOrder, cycles }
}
github kgolid / ballots / index_interactive.js View on Github external
function get_overlap_graph(boxes) {
    const nodes = [];
    boxes.forEach((box, i) => nodes.push(i));

    const edges = [];
    boxes.forEach((b1, i) => {
      boxes.forEach((b2, j) => {
        if (overlaps(b1, b2)) edges.push([i, j, b1, b2]);
      });
    });

    const overlapping = toposort(edges);
    return overlapping.reverse().map(i => boxes[i]);
  }
github neo-one-suite / neo-one / packages / neo-one-typescript-concatenator / src / Concatenator.ts View on Github external
private getAllSourceFiles(sourceFile: ts.SourceFile): readonly ts.SourceFile[] {
    const sourceFilesMap = this.getAllSourceFilesWorker(sourceFile);
    const graph = _.flatten(
      [...sourceFilesMap.entries()].map(([file, files]) =>
        files.map<[string, string]>((upstreamFile) => [file.fileName, upstreamFile.fileName]),
      ),
    );
    const sorted = _.reverse(toposort(graph));
    const filePathToSourceFile = new Map(
      [...sourceFilesMap.keys()].map((file) => [file.fileName, file] as const),
    );

    return sorted.map((filePath) => filePathToSourceFile.get(filePath)).filter(utils.notNull);
  }

toposort

Topological sort of directed ascyclic graphs (like dependecy lists)

MIT
Latest version published 6 years ago

Package Health Score

67 / 100
Full package analysis

Popular toposort functions