Skip to content

quipo/dependencysolver

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 

Dependency Resolver (Golang)

Build Status GoDoc

Introduction

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:

   A
  / \
 B   C
  \ /
   D

Resulting execution layers:

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

Installation

go get github.com/quipo/dependencysolver

Sample usage

import (
	"github.com/quipo/dependencysolver"
)

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)
}

Credits

This package follows an algorithm described (albeit incorrectly implemented) here: http://msdn.microsoft.com/en-us/magazine/dd569760.aspx

Other interesting articles on the topic:

Copyright

See LICENSE document

About

Layer-based scheduling algorithm for parallel tasks with dependencies

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages