topsort

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2021 License: Apache-2.0 Imports: 2 Imported by: 37 modules, 35 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

topsort

Topological Sorting for Golang

Topological sorting algorithms are especially useful for dependency calculation, and so this particular implementation is mainly intended for this purpose. As a result, the direction of edges and the order of the results may seem reversed compared to other implementations of topological sorting.

For example, if:

  • A depends on B
  • B depends on C

The graph is represented as:

A -> B -> C

Where -> represents a directed edge from one node to another.

The topological ordering of dependencies results in:

[C, B, A]

The code for this example would look something like:

// Initialize the graph.
graph := topsort.NewGraph()
graph.AddNode("A")
graph.AddNode("B")
graph.AddNode("C")

// Add edges.
graph.AddEdge("A", "B")
graph.AddEdge("B", "C")

// Topologically sort node A.
graph.TopSort("A")  // => [C, B, A]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Graph

type Graph struct {
	// contains filtered or unexported fields
}

func NewGraph

func NewGraph() *Graph

func (*Graph) AddEdge

func (g *Graph) AddEdge(from string, to string) error

func (*Graph) AddNode

func (g *Graph) AddNode(name string)

func (*Graph) ContainsNode

func (g *Graph) ContainsNode(name string) bool

func (*Graph) GetOrAddNode added in v0.2.0

func (g *Graph) GetOrAddNode(name string) node

func (*Graph) TopSort

func (g *Graph) TopSort(name string) ([]string, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址