// edge returns a graph with two edges (0, 1) and (1, 0).
4324
func edge() *Virtual {
	g := &Virtual{
		order:  2,
		cost:   zero,
		edge:   alwaysEdge,
		degree: degreeOne,
	}
	g.visit = func(v int, a int, do func(w int, c int64) bool) (aborted bool) {
		w := 1 - v
		if w < a {
			return
		}
		return do(w, 0)
	}
	return g
}
1216824
func (g *Virtual) Subgraph(s VertexSet) *Virtual {
	n := g.Order()
	s = s.And(Range(0, n))
	m := s.size()
	switch {
	case m == 0:
		return null
	case m == 1:
		return singleton()
	case m == n:
		return g
	}

	cost := func(v, w int) int64 {
		return g.cost(s.get(v), s.get(w))
	}
	res := generic(m, cost, func(v, w int) bool {
		return g.edge(s.get(v), s.get(w))
	})
	res.visit = func(v int, a int, do func(w int, c int64) bool) (aborted bool) {
		if a >= m {
			return
		}
		v0 := s.get(v)
		s0 := s.And(Range(s.get(a), n))
		for _, in := range s0.set {
			if more := false; g.visit(v0, in.a, func(w0 int, c int64) (skip bool) {
				switch {
				case w0 >= in.b:
					more, skip = true, true
					return
				case do(s.rank(w0), c):
					return true
				default:
					return
				}
			}) && !more {
				return true
			}
		}
		return
	}
	return res
}
389606
func _simplify(i interface{}) interface{} {

	if v, ok := i.(*Graph); ok {
		if v.Len() == 1 && v.Out[0].Len() == 0 {
			return v.Out[0].This
		}
	}
	return i
}
360548
func (g *graph) EdgeCollections(ctx context.Context) ([]Collection, []VertexConstraints, error) {
	req, err := g.conn.NewRequest("GET", g.relPath())
	if err != nil {
		return nil, nil, WithStack(err)
	}
	resp, err := g.conn.Do(ctx, req)
	if err != nil {
		return nil, nil, WithStack(err)
	}
	if err := resp.CheckStatus(200); err != nil {
		return nil, nil, WithStack(err)
	}
	var data getGraphResponse
	if err := resp.ParseBody("", &data); err != nil {
		return nil, nil, WithStack(err)
	}
	result := make([]Collection, 0, len(data.Graph.EdgeDefinitions))
	constraints := make([]VertexConstraints, 0, len(data.Graph.EdgeDefinitions))
	for _, n := range data.Graph.EdgeDefinitions {
		ec, err := newEdgeCollection(n.Collection, g)
		if err != nil {
			return nil, nil, WithStack(err)
		}
		result = append(result, ec)
		constraints = append(constraints, VertexConstraints{
			From: n.From,
			To:   n.To,
		})
	}
	return result, constraints, nil
}
1099028
func (r Rect) Edges() [4]Line {
	corners := r.Vertices()

	return [4]Line{
		{A: corners[0], B: corners[1]},
		{A: corners[1], B: corners[2]},
		{A: corners[2], B: corners[3]},
		{A: corners[3], B: corners[0]},
	}
}
859463
func (g *Graph) Interface() interface{} {
	if g.Out != nil && len(g.Out) != 0 {
		return g.Out[0].This
	}
	return nil
}
1280644
func (builder *DictEdgeBuilder) Build(context *EdgeBuildingContext) *Edge {
	builder.pointers = append(builder.pointers, &dictBuilderPointer{S: context.I})

	newIndex := 0
	for i, _ := range builder.pointers {
		newPointer := builder.updatePointer(builder.pointers[i], context.Ch)
		if newPointer != nil {
			builder.pointers[newIndex] = newPointer
			newIndex++
		}
	}

	builder.pointers = builder.pointers[:newIndex]
	var bestEdge *Edge

	for _, pointer := range builder.pointers {
		if pointer.IsFinal {
			s := 1 + context.I - pointer.Offset
			source := context.Path[s]
			edge := &Edge{
				S:         s,
				EdgeType:  DICT,
				WordCount: source.WordCount + 1,
				UnkCount:  source.UnkCount}
			if !bestEdge.IsBetterThan(edge) {
				bestEdge = edge
			}
		}
	}

	return bestEdge
}
186098
func (g Graph) SubgraphWithNodes(nodes []graph.Node, fn EdgeFunc) Graph {
	out := New()
	for _, node := range nodes {
		out.internal.AddNode(node)
	}
	out.addEdges(g.internal.Edges(), fn)
	return out
}
1315537
func (g *Mutable) Degree(v int) int {
	return len(g.edges[v])
}
14074
func (g *Immutable) Degree(v int) int {
	return len(g.edges[v])
}
155563
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
}
150479
func (self *Graph) Reset() {
	self.edges = make(map[uint32](map[uint32]float64))
	self.nodes = make(map[uint32]*node)
}
497476
func (p *Polygon) Edge(e int) Edge {
	var i int

	if len(p.cumulativeEdges) > 0 {
		for i = range p.cumulativeEdges {
			if i+1 >= len(p.cumulativeEdges) || e < p.cumulativeEdges[i+1] {
				e -= p.cumulativeEdges[i]
				break
			}
		}
	} else {
		// When the number of loops is small, use linear search. Most often
		// there is exactly one loop and the code below executes zero times.
		for i = 0; e >= len(p.Loop(i).vertices); i++ {
			e -= len(p.Loop(i).vertices)
		}
	}

	return Edge{p.Loop(i).OrientedVertex(e), p.Loop(i).OrientedVertex(e + 1)}
}
475809
func (g *UndirectedGraph) EdgeBetween(x, y graph.Node) graph.Edge {
	// We don't need to check if neigh exists because
	// it's implicit in the edges access.
	if !g.Has(x) {
		return nil
	}

	edge, _ := g.edges[x.ID()].Get(y.ID())
	return edge
}
1007033
func (builder *UnkEdgeBuilder) Build(context *EdgeBuildingContext) *Edge {
	if context.BestEdge != nil {
		return nil
	}

	source := context.Path[context.LeftBoundary]

	return &Edge{S: context.LeftBoundary,
		EdgeType:  UNK,
		WordCount: source.WordCount + 1,
		UnkCount:  source.UnkCount + 1}
}
342414
func ReverseGraphEdge(g Interface, from, to graph.Node, edgeKinds sets.String) bool {
	for edgeKind := range edgeKinds {
		g.AddEdge(to, from, edgeKind)
	}
	return false
}
972702
func EdgesOfKind(kinds ...string) EdgeFunc {
	if len(kinds) == 0 {
		return func(g Interface, from, to graph.Node, edgeKinds sets.String) bool {
			return true
		}
	}

	allowedKinds := sets.NewString(kinds...)
	return func(g Interface, from, to graph.Node, edgeKinds sets.String) bool {
		return allowedKinds.HasAny(edgeKinds.List()...)
	}
}