Skip to content

haavistu/dependency-solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dependency Solver

Build Status

A tiny dependency solver using topological sorting. Returns a list of nodes where no node comes before it's dependencies.

dep-solver

Usage

Nodes can be in any order. Any valid property name is a valid node. Circular dependencies throw an error.

var { solve } = require('dependency-solver');

var graph = {
    'A': ['B', 'C', 'F'],
    'B': ['C', 'D'],
    'F': ['E'],
    'C': ['D', 'E']
}

solve(graph);
// -> [ 'D', 'E', 'C', 'B', 'F', 'A' ]

You can also compute how many nodes depend on a particular node and dependency lines between nodes.

var { getDependedBy, getDependencyLines } = require('dependency-solver');

getDependedBy(graph);
// -> { 'B': 1, 
//      'A': 0, 
//      'C': 2, 
//      'F': 1, 
//      'D': 2, 
//      'E': 2 }

getDependencyLines(graph);
// -> [ [ 'A', 'B' ],
//      [ 'A', 'C' ],
//      [ 'A', 'F' ],
//      [ 'B', 'C' ],
//      [ 'B', 'D' ],
//      [ 'F', 'E' ],
//      [ 'C', 'D' ],
//      [ 'C', 'E' ] ]

License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

A tiny dependency solver using topological sorting

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published