func (g *Graph) UpEdges(v Vertex) *Set {
	g.init()
	return g.upEdges[hashcode(v)]
}
UpEdges returns the inward edges to the destination Vertex v.
package dag
import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"sort"
)
type Graph struct {
	vertices  *Set
	edges     *Set
	downEdges map[interface{}]*Set
	upEdges   map[interface{}]*Set
	debug *encoder
}
type Subgrapher interface {
	Subgraph() Grapher
}
type Grapher interface {
	DirectedGraph() Grapher
}
type Vertex interface{}
type NamedVertex interface {
	Vertex
	Name() string
}
func (g *Graph) DirectedGraph() Grapher {
	return g
}
func (g *Graph) Vertices() []Vertex {
	list := g.vertices.List()
	result := make([]Vertex, len(list))
	for i, v := range list {
		result[i] = v.(Vertex)
	}
	return result
}
func (g *Graph) Edges() []Edge {
	list := g.edges.List()
	result := make([]Edge, len(list))
	for i, v := range list {
		result[i] = v.(Edge)
	}
	return result
}
func (g *Graph) EdgesFrom(v Vertex) []Edge {
	var result []Edge
	from := hashcode(v)
	for _, e := range g.Edges() {
		if hashcode(e.Source()) == from {
			result = append(result, e)
		}
	}
	return result
}
func (g *Graph) EdgesTo(v Vertex) []Edge {
	var result []Edge
	search := hashcode(v)
	for _, e := range g.Edges() {
		if hashcode(e.Target()) == search {
			result = append(result, e)
		}
	}
	return result
}
func (g *Graph) HasVertex(v Vertex) bool {
	return g.vertices.Include(v)
}
func (g *Graph) HasEdge(e Edge) bool {
	return g.edges.Include(e)
}
func (g *Graph) Add(v Vertex) Vertex {
	g.init()
	g.vertices.Add(v)
	g.debug.Add(v)
	return v
}
func (g *Graph) Remove(v Vertex) Vertex {
	g.vertices.Delete(v)
	g.debug.Remove(v)
	for _, target := range g.DownEdges(v).List() {
		g.RemoveEdge(BasicEdge(v, target))
	}
	for _, source := range g.UpEdges(v).List() {
		g.RemoveEdge(BasicEdge(source, v))
	}
	return nil
}
func (g *Graph) Replace(original, replacement Vertex) bool {
	if !g.vertices.Include(original) {
		return false
	}
	defer g.debug.BeginOperation("Replace", "").End("")
	if original == replacement {
		return true
	}
	g.Add(replacement)
	for _, target := range g.DownEdges(original).List() {
		g.Connect(BasicEdge(replacement, target))
	}
	for _, source := range g.UpEdges(original).List() {
		g.Connect(BasicEdge(source, replacement))
	}
	g.Remove(original)
	return true
}
func (g *Graph) RemoveEdge(edge Edge) {
	g.init()
	g.debug.RemoveEdge(edge)
	g.edges.Delete(edge)
	if s, ok := g.downEdges[hashcode(edge.Source())]; ok {
		s.Delete(edge.Target())
	}
	if s, ok := g.upEdges[hashcode(edge.Target())]; ok {
		s.Delete(edge.Source())
	}
}
func (g *Graph) DownEdges(v Vertex) *Set {
	g.init()
	return g.downEdges[hashcode(v)]
}