Update vendor/

This commit is contained in:
Ettore Di Giacinto
2019-11-09 10:47:44 +01:00
parent f7efbe23f2
commit 383efe3c99
5 changed files with 176 additions and 0 deletions

6
vendor/github.com/philopon/go-toposort/.travis.yml generated vendored Normal file
View File

@@ -0,0 +1,6 @@
language: go
go:
- 1.5
- 1.6
- 1.7
- master

7
vendor/github.com/philopon/go-toposort/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,7 @@
Copyright 2017 Hirotomo Moriwaki
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

53
vendor/github.com/philopon/go-toposort/README.md generated vendored Normal file
View File

@@ -0,0 +1,53 @@
go-toposort
==
[![Build Status](https://travis-ci.org/philopon/go-toposort.svg?branch=master)](https://travis-ci.org/philopon/go-toposort)
[![GoDoc](https://godoc.org/github.com/philopon/go-toposort?status.svg)](https://godoc.org/github.com/philopon/go-toposort)
deterministic topological sort implementation for golang
Example
--
```.go
package main
import (
"fmt"
toposort "github.com/philopon/go-toposort"
)
func main() {
graph := toposort.NewGraph(8)
graph.AddNodes("2", "3", "5", "7", "8", "9", "10", "11")
graph.AddEdge("7", "8")
graph.AddEdge("7", "11")
graph.AddEdge("5", "11")
graph.AddEdge("3", "8")
graph.AddEdge("3", "10")
graph.AddEdge("11", "2")
graph.AddEdge("11", "9")
graph.AddEdge("11", "10")
graph.AddEdge("8", "9")
result, ok := graph.Toposort()
if !ok {
panic("cycle detected")
}
fmt.Println(result)
}
```
```
[3 5 7 8 11 2 9 10]
```
License
--
MIT

101
vendor/github.com/philopon/go-toposort/toposort.go generated vendored Normal file
View File

@@ -0,0 +1,101 @@
package toposort
type Graph struct {
nodes []string
outputs map[string]map[string]int
inputs map[string]int
}
func NewGraph(cap int) *Graph {
return &Graph{
nodes: make([]string, 0, cap),
inputs: make(map[string]int),
outputs: make(map[string]map[string]int),
}
}
func (g *Graph) AddNode(name string) bool {
g.nodes = append(g.nodes, name)
if _, ok := g.outputs[name]; ok {
return false
}
g.outputs[name] = make(map[string]int)
g.inputs[name] = 0
return true
}
func (g *Graph) AddNodes(names ...string) bool {
for _, name := range names {
if ok := g.AddNode(name); !ok {
return false
}
}
return true
}
func (g *Graph) AddEdge(from, to string) bool {
m, ok := g.outputs[from]
if !ok {
return false
}
m[to] = len(m) + 1
g.inputs[to]++
return true
}
func (g *Graph) unsafeRemoveEdge(from, to string) {
delete(g.outputs[from], to)
g.inputs[to]--
}
func (g *Graph) RemoveEdge(from, to string) bool {
if _, ok := g.outputs[from]; !ok {
return false
}
g.unsafeRemoveEdge(from, to)
return true
}
func (g *Graph) Toposort() ([]string, bool) {
L := make([]string, 0, len(g.nodes))
S := make([]string, 0, len(g.nodes))
for _, n := range g.nodes {
if g.inputs[n] == 0 {
S = append(S, n)
}
}
for len(S) > 0 {
var n string
n, S = S[0], S[1:]
L = append(L, n)
ms := make([]string, len(g.outputs[n]))
for m, i := range g.outputs[n] {
ms[i-1] = m
}
for _, m := range ms {
g.unsafeRemoveEdge(n, m)
if g.inputs[m] == 0 {
S = append(S, m)
}
}
}
N := 0
for _, v := range g.inputs {
N += v
}
if N > 0 {
return L, false
}
return L, true
}