// Graph returns an existing graph if available. Getting a non existing
// graph should return an error.
556685
func (s *memoryStore) Graph(ctx context.Context, id string) (storage.Graph, error) {
	s.rwmu.RLock()
	defer s.rwmu.RUnlock()
	if g, ok := s.graphs[id]; ok {
		return g, nil
	}
	return nil, fmt.Errorf("memory.Graph(%q): graph does not exist", id)
}
712543
func (g *Graph) flow() {
	n := 0
	var nod *Graph

	for i := 0; i < g.Len(); i++ {

		node := g.Out[i]
		s := node.ThisString()

		if s == TypeIf || s == TypeFor {
			n++
			if n == 1 {
				nod = node.Add(TypeTemplate)
				continue
			}
		}

		if s == TypeElse {
			if n == 1 {
				nod.flow()
				nod = node
				continue
			}
		}

		if s == TypeEnd {
			n--
			if n == 0 {
				nod.flow()
				g.DeleteAt(i)
				i--
				continue
			}
		}

		if n > 0 {
			nod.Add(node)
			g.DeleteAt(i)
			i--
		}
	}

}
1126242
func (g *UndirectedGraph) Has(n graph.Node) bool {
	_, ok := g.nodes[n.ID()]
	return ok
}
653904
func New(prof *profile.Profile, o *Options) *Graph {
	if o.CallTree {
		return newTree(prof, o)
	}
	g, _ := newGraph(prof, o)
	return g
}
690720
func newGraph(prof *profile.Profile, o *Options) (*Graph, map[uint64]Nodes) {
	nodes, locationMap := CreateNodes(prof, o)
	for _, sample := range prof.Sample {
		var w, dw int64
		w = o.SampleValue(sample.Value)
		if o.SampleMeanDivisor != nil {
			dw = o.SampleMeanDivisor(sample.Value)
		}
		if dw == 0 && w == 0 {
			continue
		}
		seenNode := make(map[*Node]bool, len(sample.Location))
		seenEdge := make(map[nodePair]bool, len(sample.Location))
		var parent *Node
		// A residual edge goes over one or more nodes that were not kept.
		residual := false

		labels := joinLabels(sample)
		// Group the sample frames, based on a global map.
		for i := len(sample.Location) - 1; i >= 0; i-- {
			l := sample.Location[i]
			locNodes := locationMap[l.ID]
			for ni := len(locNodes) - 1; ni >= 0; ni-- {
				n := locNodes[ni]
				if n == nil {
					residual = true
					continue
				}
				// Add cum weight to all nodes in stack, avoiding double counting.
				if _, ok := seenNode[n]; !ok {
					seenNode[n] = true
					n.addSample(dw, w, labels, sample.NumLabel, sample.NumUnit, o.FormatTag, false)
				}
				// Update edge weights for all edges in stack, avoiding double counting.
				if _, ok := seenEdge[nodePair{n, parent}]; !ok && parent != nil && n != parent {
					seenEdge[nodePair{n, parent}] = true
					parent.AddToEdgeDiv(n, dw, w, residual, ni != len(locNodes)-1)
				}
				parent = n
				residual = false
			}
		}
		if parent != nil && !residual {
			// Add flat weight to leaf node.
			parent.addSample(dw, w, labels, sample.NumLabel, sample.NumUnit, o.FormatTag, true)
		}
	}

	return selectNodesForGraph(nodes, o.DropNegative), locationMap
}
1327851
func (g *UndirectedGraph) RemoveEdge(e graph.Edge) {
	from, to := e.From(), e.To()
	if _, ok := g.nodes[from.ID()]; !ok {
		return
	}
	if _, ok := g.nodes[to.ID()]; !ok {
		return
	}

	g.edges[from.ID()] = g.edges[from.ID()].Delete(to.ID())
	g.edges[to.ID()] = g.edges[to.ID()].Delete(from.ID())
}
1023877
func (g *Graph) Dot(opts *DotOpts) []byte {
	return newMarshalGraph("", g).Dot(opts)
}
238299
func (gt GraphType) String() string {
	if gt == DIGRAPH {
		return "digraph"
	} else if gt == GRAPH {
		return "graph"
	} else if gt == SUBGRAPH {
		return "subgraph"
	}
	return "(invalid)"
}
334284
func (g *Graph) Node(s string) *Graph {
	if g == nil || g.Out == nil {
		return nil
	}
	for _, node := range g.Out {
		if s == _string(node.This) {
			return node
		}
	}

	return nil
}
1100420
func Graph(disableList []string) (ordered []*Registration) {
	register.RLock()
	defer register.RUnlock()
	for _, d := range disableList {
		for i, r := range register.r {
			if r.ID == d {
				register.r = append(register.r[:i], register.r[i+1:]...)
				break
			}
		}
	}

	added := map[*Registration]bool{}
	for _, r := range register.r {

		children(r.ID, r.Requires, added, &ordered)
		if !added[r] {
			ordered = append(ordered, r)
			added[r] = true
		}
	}
	return ordered
}
1271314
func (l *Loop) Edge(i int) Edge {
	return Edge{l.Vertex(i), l.Vertex(i + 1)}
}
133290
func (g *UndirectedGraph) Degree(n graph.Node) int {
	if _, ok := g.nodes[n.ID()]; !ok {
		return 0
	}

	return g.edges[n.ID()].Len()
}
1196113
func (r Metric_Tracking_Object) GetGraph(startDateTime *datatypes.Time, endDateTime *datatypes.Time, graphType []string) (resp datatypes.Container_Bandwidth_GraphOutputs, err error) {
	params := []interface{}{
		startDateTime,
		endDateTime,
		graphType,
	}
	err = r.Session.DoRequest("SoftLayer_Metric_Tracking_Object", "getGraph", params, &r.Options, &resp)
	return
}
48479
func (g *Graph) Node(k *Key) (*Node, error) {
	if !g.finalized {
		return nil, ErrNotFinalized
	}
	if err := g.validateKey("key", k); err != nil {
		return nil, err
	}
	switch n := g.nodes[k]; {
	case n == nil:
		return nil, nil
	case !n.Declared():
		panic(fmt.Errorf("impossible not-yet-declared node in a finalized graph: %s", n.Key))
	default:
		return n, nil
	}
}
388156
func (log *Log) Get(i int64) (*Graph, int64, error) {

	/* Position in file */
	_, err := log.f.Seek(i, 0)
	if err != nil {
		return nil, -1, err
	}

	p := newBinParser(log.f)
	g := p.parse()

	if p.n == 0 {
		return g, -1, nil
	}

	return g, i + int64(p.n), err
}
1151629
func (g *Graph) AddNodes(g2 *Graph) *Graph {

	if g == nil {
		return nil
	}

	if g2 != nil {
		g.Out = append(g.Out, g2.Out...)
	}
	return g
}
1204094
func (b *blame) sliceGraph(i int) []*object.Commit {
	fVs := b.graph[i]
	result := make([]*object.Commit, 0, len(fVs))
	for _, v := range fVs {
		c := object.Commit(*v)
		result = append(result, &c)
	}
	return result
}