// must be called under write lock
// deletes edges from a given vertex type to a specific vertex
// will delete each orphaned "from" vertex, but will never delete the "to" vertex
503335
func (g *Graph) deleteEdges_locked(fromType, toType vertexType, toNamespace, toName string) {
	// get the "to" side
	toVert, exists := g.getVertex_rlocked(toType, toNamespace, toName)
	if !exists {
		return
	}

	// delete all edges between vertices of fromType and toVert
	neighborsToRemove := []*namedVertex{}
	neighborsToRecompute := []*namedVertex{}
	g.graph.VisitTo(toVert, func(from graph.Node) bool {
		fromVert := from.(*namedVertex)
		if fromVert.vertexType != fromType {
			return true
		}
		// remove the edge
		g.graph.RemoveEdge(simple.Edge{F: fromVert, T: toVert})
		// track vertexes that changed edges
		if g.graph.Degree(fromVert) == 0 {
			neighborsToRemove = append(neighborsToRemove, fromVert)
		} else {
			neighborsToRecompute = append(neighborsToRecompute, fromVert)
		}
		return true
	})

	// clean up orphaned verts
	for _, v := range neighborsToRemove {
		g.removeVertex_locked(v)
	}

	// recompute destination indexes for neighbors that dropped outbound edges
	for _, v := range neighborsToRecompute {
		g.recomputeDestinationIndex_locked(v)
	}
}
979927
func (g *Graph) Delete(n interface{}) {

	if g == nil {
		return
	}
	for i := 0; i < g.Len(); i++ {
		if g.Out[i].This == n {
			if i < (g.Len() - 1) {
				g.Out = append(g.Out[:i], g.Out[i+1:]...)
			} else {
				g.Out = g.Out[:i]
			}
			i--
		}
	}
}
630931
func (p *Polyline) Edge(i int) Edge {
	return Edge{(*p)[i], (*p)[i+1]}
}
103953
func dropEdge(src node, dest node) {
	if DEBUG_MESSAGES {
		print("dropping edge from ", src.id(), "->", dest.id())
	}
	src.removeOut(dest.id())
	dest.removeIn(src.id())
	dest.markDirty()
}
1159192
func (s *ShapeIndex) countShapes(edges []*clippedEdge, shapeIDs []int32) int {
	count := 0
	lastShapeID := int32(-1)

	// next clipped shape id in the shapeIDs list.
	clippedNext := int32(0)
	// index of the current element in the shapeIDs list.
	shapeIDidx := 0
	for _, edge := range edges {
		if edge.faceEdge.shapeID == lastShapeID {
			continue
		}

		count++
		lastShapeID = edge.faceEdge.shapeID

		// Skip over any containing shapes up to and including this one,
		// updating count as appropriate.
		for ; shapeIDidx < len(shapeIDs); shapeIDidx++ {
			clippedNext = shapeIDs[shapeIDidx]
			if clippedNext > lastShapeID {
				break
			}
			if clippedNext < lastShapeID {
				count++
			}
		}
	}

	// Count any remaining containing shapes.
	count += int(len(shapeIDs)) - int(shapeIDidx)
	return count
}
157627
func (g *UndirectedGraph) SetEdge(e graph.Edge) {
	var (
		from = e.From()
		fid  = from.ID()
		to   = e.To()
		tid  = to.ID()
	)

	if fid == tid {
		panic("simple: adding self edge")
	}

	if !g.Has(from) {
		g.AddNode(from)
	}
	if !g.Has(to) {
		g.AddNode(to)
	}

	g.edges[fid] = g.edges[fid].Set(tid, e)
	g.edges[tid] = g.edges[tid].Set(fid, e)
}
433146
func WriteDot(w io.Writer, nodes []Node) error {
	w.Write([]byte("digraph {\n"))
	defer w.Write([]byte("}\n"))

	for _, n := range nodes {
		nodeLine := fmt.Sprintf("\t\"%s\";\n", n)

		w.Write([]byte(nodeLine))

		for _, edge := range n.Edges() {
			target := edge.Tail()
			line := fmt.Sprintf("\t\"%s\" -> \"%s\" [label=\"%s\"];\n",
				n, target, edge)
			w.Write([]byte(line))
		}
	}

	return nil
}
943856
func (g Graph) SuccessorNodesByEdgeKind(node graph.Node, edgeKinds ...string) []graph.Node {
	ret := []graph.Node{}

	for _, outboundEdge := range g.OutboundEdges(node, edgeKinds...) {
		ret = append(ret, outboundEdge.To())
	}

	return ret
}
894756
func DeleteEdges(mu *api.Mutation, uid string, predicates ...string) {
	for _, predicate := range predicates {
		mu.Del = append(mu.Del, &api.NQuad{
			Subject:   uid,
			Predicate: predicate,
			// _STAR_ALL is defined as x.Star in x package.
			ObjectValue: &api.Value{Val: &api.Value_DefaultVal{"_STAR_ALL"}},
		})
	}
}
1118954
func (g *Graph) Clear() {

	if g == nil || g.Out == nil {
		return
	}
	g.Out = nil
}
1354592
func (g *Graph) UpEdges(v Vertex) *Set {
	g.init()
	return g.upEdges[hashcode(v)]
}
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
}
1139113
func (g *Immutable) Edge(v, w int) bool {
	if v < 0 || v >= len(g.edges) {
		return false
	}
	edges := g.edges[v]
	n := len(edges)
	i := sort.Search(n, func(i int) bool { return w <= edges[i].vertex })
	return i < n && w == edges[i].vertex
}
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
}
582553
func (e *joinReOrderSolver) walkGraphAndComposeJoin(u int) {
	e.visited[u] = true
	for _, edge := range e.graph[u] {
		v := edge.nodeID
		if !e.visited[v] {
			e.resultJoin = e.newJoin(e.resultJoin, e.group[v])
			e.walkGraphAndComposeJoin(v)
		}
	}
}
119875
func (rw *RefWriter) WriteEdge(from, to cid.Cid, linkname string, enc cidenc.Encoder) error {
	if rw.Ctx != nil {
		select {
		case <-rw.Ctx.Done(): // just in case.
			return rw.Ctx.Err()
		default:
		}
	}

	var s string
	switch {
	case rw.PrintFmt != "":
		s = rw.PrintFmt
		s = strings.Replace(s, "<src>", enc.Encode(from), -1)
		s = strings.Replace(s, "<dst>", enc.Encode(to), -1)
		s = strings.Replace(s, "<linkname>", linkname, -1)
	default:
		s += enc.Encode(to)
	}

	return rw.res.Emit(&RefWrapper{Ref: s})
}
207399
func BasicEdge(source, target Vertex) Edge {
	return &basicEdge{S: source, T: target}
}