Layer-based scheduling algorithm for parallel tasks with dependencies
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Dependency Resolver (Golang)

Build Status GoDoc


Layer-based scheduling algorithm for parallel tasks with dependencies. Determines which tasks can be executed in parallel, by evaluating dependencies.

Given a list of entries (each with its own dependency list), it can sort them in layers of execution, where all entries in the same layer can be executed in parallel, and have no other dependency than the previous layer.

For instance, given entries A, B, C, D, where B and C depend on A, and D depends on B and C, this function will return three layers of execution (as B and C can be executed in parallel after A completes):

Dependency tree:

  / \
 B   C
  \ /

Resulting execution layers:

Layer 1:       A
Layer 2:     B   C
Layer 3:       D


go get

Sample usage

import (

type Operation struct {
	ID   string,
	Deps []string,
	// some other properties of the operation	

func SortByDependency(operations []Operation) (layers [][]string) {
	entries := make([]dependencysolver.Entry, 0)
	for _, op := range operations {
		entries = append(entries, dependencysolver.Entry{ID: op.ID, Deps: op.Deps})
	return dependencysolver.LayeredTopologicalSort(entries)


This package follows an algorithm described (albeit incorrectly implemented) here:

Other interesting articles on the topic:


See LICENSE document