func FindSources(g gogl.Digraph) (sources []gogl.Vertex, err error) {
	incomings := set.New(set.NonThreadSafe)
	g.Arcs(func(e gogl.Arc) (terminate bool) {
		incomings.Add(e.Target())
		return
	})
	g.Vertices(func(v gogl.Vertex) (terminate bool) {
		if !incomings.Has(v) {
			sources = append(sources, v)
		}
		return
	})
	return
}
Finds all source vertices (vertices with no incoming edges) in the given directed graph.
package dfs
import (
	"errors"
	"github.com/sdboyer/gogl"
	"gopkg.in/fatih/set.v0"
)
const (
	white = iota
	grey
	black
)
func Search(g gogl.Graph, target gogl.Vertex, start gogl.Vertex) (path []gogl.Vertex, err error) {
	if !g.HasVertex(target) {
		return nil, errors.New("Target vertex is not present in graph.")
	}
	if !g.HasVertex(start) {
		return nil, errors.New("Start vertex is not present in graph.")
	}
	visitor := &searchVisitor{}
	w := walker{
		vis:    visitor,
		g:      g,
		colors: make(map[gogl.Vertex]uint),
		target: target,
	}
	if dg, ok := g.(gogl.Digraph); ok {
		w.dg = dg
	}
	w.dfsearch(start)
	return visitor.getPath(), nil
}
func multiSearch(g gogl.Graph, target gogl.Vertex, start ...gogl.Vertex) (pathchan chan<- *searchPath, err error) {
	start, err = buildStartQueue(g)
	if err != nil {
		return nil, err
	}
	return
}
type searchPath struct {
	Start     gogl.Vertex
	Target    gogl.Vertex
	Reachable bool
	Path      []gogl.Vertex
}
func Toposort(g gogl.Graph, start ...gogl.Vertex) ([]gogl.Vertex, error) {
	start, err := buildStartQueue(g, start...)
	if err != nil {
		return nil, err
	}
	stack := vstack{}
	for _, v := range start {
		stack.push(v)
	}
	if stack.length() == 0 {
		return nil, errors.New("No vertices provided as start points, cannot traverse.")
	}
	var capacity int
	if c, ok := g.(gogl.VertexCounter); ok {
		capacity = c.Order()
	} else {
		capacity = 32
	}
	visitor := &TslVisitor{tsl: make([]gogl.Vertex, 0, capacity)}
	w := &walker{
		vis:    visitor,
		g:      g,
		colors: make(map[gogl.Vertex]uint),
	}
	var traverser func(*walker, gogl.Vertex)
	if dg, ok := g.(gogl.Digraph); ok {
		w.dg = dg
		traverser = (*walker).dftraverse
	} else {
		traverser = (*walker).dfutraverse
	}
	for v := stack.pop(); ; {
		traverser(w, v)
		if stack.length() == 0 {
			break
		}
	}
	return visitor.GetTsl()
}
func Traverse(g gogl.Graph, visitor Visitor, start ...gogl.Vertex) (Visitor, error) {
	start, err := buildStartQueue(g, start...)
	if err != nil {
		return nil, err
	}
	stack := vstack{}
	for _, v := range start {
		stack.push(v)
	}
	w := &walker{
		vis:    visitor,
		g:      g,
		colors: make(map[gogl.Vertex]uint),
	}
	if dg, ok := g.(gogl.Digraph); ok {
		w.dg = dg
	}
	for v := stack.pop(); ; {
		w.dftraverse(v)
		if stack.length() == 0 {
			break
		}
	}
	return visitor, nil
}