toposort

package module
v0.0.0-...-8cdc623 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2017 License: MIT Imports: 1 Imported by: 0

README

go-toposort

Topological sorting implementation in Go

Installation

$ go get github.com/vbogretsov/go-toposort

Usage

package main

import (
    "fmt"
    "log"

    "github.com/vbogretsov/go-toposort"
)

func main() {
    graph := toposort.NewGraph()
    graph.AddNode("f0")
    graph.AddNode("f1")
    graph.AddNode("f2")
    graph.AddNode("f3")
    graph.AddEdge("f1", "f0")
    graph.AddEdge("f3", "f2")
    graph.AddEdge("f2", "f1")
    graph.AddEdge("f3", "f1")

    order, err := graph.Resolve("f3")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(order)
}

Output:

$ ./main
[f0 f1 f2 f3]

Licence

See the LICENSE file.

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 interface{}, to interface{})

func (*Graph) AddNode

func (g *Graph) AddNode(v interface{})

func (*Graph) Resolve

func (g *Graph) Resolve(vertex interface{}) ([]interface{}, error)

Jump to

Keyboard shortcuts

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