// newEdgeLocator extracts an edgeLocator based for a full edge policy
// structure.
175446
func newEdgeLocator(edge *channeldb.ChannelEdgePolicy) *EdgeLocator {
	return &EdgeLocator{
		ChannelID: edge.ChannelID,
		Direction: uint8(edge.ChannelFlags & lnwire.ChanUpdateDirection),
	}
}
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)
}
983149
func newMapping(prof *profile.Profile, obj plugin.ObjTool, ui plugin.UI, force bool) (*mappingTable, error) {
	mt := &mappingTable{
		prof:     prof,
		segments: make(map[*profile.Mapping]plugin.ObjFile),
	}

	// Identify used mappings
	mappings := make(map[*profile.Mapping]bool)
	for _, l := range prof.Location {
		mappings[l.Mapping] = true
	}

	for _, m := range prof.Mapping {
		if !mappings[m] {
			continue
		}
		// Do not attempt to re-symbolize a mapping that has already been symbolized.
		if !force && (m.HasFunctions || m.HasFilenames || m.HasLineNumbers) {
			continue
		}

		f, err := locateFile(obj, m.File, m.BuildID, m.Start)
		if err != nil {
			ui.PrintErr("Local symbolization failed for ", filepath.Base(m.File), ": ", err)
			// Move on to other mappings
			continue
		}

		if fid := f.BuildID(); m.BuildID != "" && fid != "" && fid != m.BuildID {
			// Build ID mismatch - ignore.
			f.Close()
			continue
		}

		mt.segments[m] = f
	}

	return mt, nil
}
993601
func (ci CellID) EdgeNeighbors() [4]CellID {
	level := ci.Level()
	size := sizeIJ(level)
	f, i, j, _ := ci.faceIJOrientation()
	return [4]CellID{
		cellIDFromFaceIJWrap(f, i, j-size).Parent(level),
		cellIDFromFaceIJWrap(f, i+size, j).Parent(level),
		cellIDFromFaceIJWrap(f, i, j+size).Parent(level),
		cellIDFromFaceIJWrap(f, i-size, j).Parent(level),
	}
}
920539
func NewDetector(location string, pool *redis.Pool, strategy Strategy) Detector {
	return SimpleDetector{
		location: location,
		pool:     pool,
		strategy: strategy,
	}
}
282134
func NewEndpointServiceResolver(services listersv1.ServiceLister, endpoints listersv1.EndpointsLister) ServiceResolver {
	return &aggregatorEndpointRouting{
		services:  services,
		endpoints: endpoints,
	}
}
1344128
func NewRouter() Router {
	return &router{
		gateways: make(map[string]*gateway.Gateway),
		brokers:  make(map[string]*broker),
	}
}
207399
func BasicEdge(source, target Vertex) Edge {
	return &basicEdge{S: source, T: target}
}
1320842
func NewPinger(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (Pinger, error) {
	pingTimeout, ok := resources.Get("pingTimeout").(*pingTimeout)
	if !ok {
		return nullPinger{}, nil
	}
	return pingTimeout, nil
}
1078765
func NewLineStroker(c LineCap, j LineJoin, flattener Flattener) *LineStroker {
	l := new(LineStroker)
	l.Flattener = flattener
	l.HalfLineWidth = 0.5
	l.Cap = c
	l.Join = j
	return l
}
283658
func newEdge(logger *zap.Logger, meter *metrics.Scope, req *transport.Request, direction string) *edge {
	tags := metrics.Tags{
		"source":           req.Caller,
		"dest":             req.Service,
		"transport":        unknownIfEmpty(req.Transport),
		"procedure":        req.Procedure,
		"encoding":         string(req.Encoding),
		"routing_key":      req.RoutingKey,
		"routing_delegate": req.RoutingDelegate,
		"direction":        direction,
	}
	calls, err := meter.Counter(metrics.Spec{
		Name:      "calls",
		Help:      "Total number of RPCs.",
		ConstTags: tags,
	})
	if err != nil {
		logger.Error("Failed to create calls counter.", zap.Error(err))
	}
	successes, err := meter.Counter(metrics.Spec{
		Name:      "successes",
		Help:      "Number of successful RPCs.",
		ConstTags: tags,
	})
	if err != nil {
		logger.Error("Failed to create successes counter.", zap.Error(err))
	}
	callerFailures, err := meter.CounterVector(metrics.Spec{
		Name:      "caller_failures",
		Help:      "Number of RPCs failed because of caller error.",
		ConstTags: tags,
		VarTags:   []string{_error},
	})
	if err != nil {
		logger.Error("Failed to create caller failures vector.", zap.Error(err))
	}
	serverFailures, err := meter.CounterVector(metrics.Spec{
		Name:      "server_failures",
		Help:      "Number of RPCs failed because of server error.",
		ConstTags: tags,
		VarTags:   []string{_error},
	})
	if err != nil {
		logger.Error("Failed to create server failures vector.", zap.Error(err))
	}
	latencies, err := meter.Histogram(metrics.HistogramSpec{
		Spec: metrics.Spec{
			Name:      "success_latency_ms",
			Help:      "Latency distribution of successful RPCs.",
			ConstTags: tags,
		},
		Unit:    time.Millisecond,
		Buckets: _bucketsMs,
	})
	if err != nil {
		logger.Error("Failed to create success latency distribution.", zap.Error(err))
	}
	callerErrLatencies, err := meter.Histogram(metrics.HistogramSpec{
		Spec: metrics.Spec{
			Name:      "caller_failure_latency_ms",
			Help:      "Latency distribution of RPCs failed because of caller error.",
			ConstTags: tags,
		},
		Unit:    time.Millisecond,
		Buckets: _bucketsMs,
	})
	if err != nil {
		logger.Error("Failed to create caller failure latency distribution.", zap.Error(err))
	}
	serverErrLatencies, err := meter.Histogram(metrics.HistogramSpec{
		Spec: metrics.Spec{
			Name:      "server_failure_latency_ms",
			Help:      "Latency distribution of RPCs failed because of server error.",
			ConstTags: tags,
		},
		Unit:    time.Millisecond,
		Buckets: _bucketsMs,
	})
	if err != nil {
		logger.Error("Failed to create server failure latency distribution.", zap.Error(err))
	}
	logger = logger.With(
		zap.String("source", req.Caller),
		zap.String("dest", req.Service),
		zap.String("transport", unknownIfEmpty(req.Transport)),
		zap.String("procedure", req.Procedure),
		zap.String("encoding", string(req.Encoding)),
		zap.String("routingKey", req.RoutingKey),
		zap.String("routingDelegate", req.RoutingDelegate),
		zap.String("direction", direction),
	)
	return &edge{
		logger:             logger,
		calls:              calls,
		successes:          successes,
		callerFailures:     callerFailures,
		serverFailures:     serverFailures,
		latencies:          latencies,
		callerErrLatencies: callerErrLatencies,
		serverErrLatencies: serverErrLatencies,
	}
}
669139
func NewARPCollector() (Collector, error) {
	return &arpCollector{
		entries: prometheus.NewDesc(
			prometheus.BuildFQName(namespace, "arp", "entries"),
			"ARP entries by device",
			[]string{"device"}, nil,
		),
	}, nil
}
706225
func NewRoundTripper(ctx log.Interface, headers map[string]string) *RoundTripper {
	return &RoundTripper{
		ctx:       ctx,
		transport: http.DefaultTransport,
		headers:   headers,
	}
}
464843
func newEdge(src node, dest node) *edgeImpl {
	e := &edgeImpl{
		s:         src,
		d:         dest,
		notMarked: false,
	}
	src.addOut(e)
	dest.addIn(e)
	return e
}
1290476
func newEdges(n int, e EdgeSet) *Virtual {
	switch {
	case n < 0:
		return nil
	case n == 0:
		return null
	case n == 1:
		return singleton()
	}

	var noCost bool
	if e.Cost == nil {
		noCost = true
		e.Cost = zero
	}
	var noFilter bool
	if e.Keep == nil {
		noFilter = true
		e.Keep = alwaysEdge
	}

	from := e.From.And(Range(0, n))
	to := e.To.And(Range(0, n))
	if from.size() == 0 || to.size() == 0 {
		return Empty(n)
	}
	res := generic(n, e.Cost, func(v, w int) (edge bool) {
		return e.Contains(v, w)
	})

	intersect := from.And(to)
	union := from.Or(to)
	if noFilter {
		res.degree = func(v int) (deg int) {
			switch {
			case intersect.Contains(v):
				return union.size() - 1
			case from.Contains(v):
				return to.size()
			case to.Contains(v):
				return from.size()
			default:
				return
			}
		}
	}

	visit := func(v int, a int, do func(w int, c int64) bool) (aborted bool) {
		switch {
		case intersect.Contains(v):
			for _, in := range union.And(Range(a, n)).set {
				for w := in.a; w < in.b; w++ {
					if v != w && e.Keep(v, w) && do(w, e.Cost(v, w)) {
						return true
					}
				}
			}
			return
		case from.Contains(v):
			for _, in := range to.And(Range(a, n)).set {
				for w := in.a; w < in.b; w++ {
					if e.Keep(v, w) && do(w, e.Cost(v, w)) {
						return true
					}
				}
			}
			return
		case to.Contains(v):
			for _, in := range from.And(Range(a, n)).set {
				for w := in.a; w < in.b; w++ {
					if e.Keep(v, w) && do(w, e.Cost(v, w)) {
						return true
					}
				}
			}
			return
		default:
			return
		}
	}

	visit0 := func(v int, a int, do func(w int, c int64) bool) (aborted bool) {
		switch {
		case intersect.Contains(v):
			for _, in := range union.And(Range(a, n)).set {
				for w := in.a; w < in.b; w++ {
					if v != w && e.Keep(v, w) && do(w, 0) {
						return true
					}
				}
			}
			return
		case from.Contains(v):
			for _, in := range to.And(Range(a, n)).set {
				for w := in.a; w < in.b; w++ {
					if e.Keep(v, w) && do(w, 0) {
						return true
					}
				}
			}
			return
		case to.Contains(v):
			for _, in := range from.And(Range(a, n)).set {
				for w := in.a; w < in.b; w++ {
					if e.Keep(v, w) && do(w, 0) {
						return true
					}
				}
			}
			return
		default:
			return
		}
	}

	if noCost {
		res.visit = visit0
	} else {
		res.visit = visit
	}
	return res
}
635511
func NewRouter(logger *log.Logger, localDatacenter string) *Router {
	router := &Router{
		logger:          logger,
		localDatacenter: localDatacenter,
		areas:           make(map[types.AreaID]*areaInfo),
		managers:        make(map[string][]*Manager),
	}

	// Hook the direct route lookup by default.
	router.routeFn = router.findDirectRoute

	return router
}
630931
func (p *Polyline) Edge(i int) Edge {
	return Edge{(*p)[i], (*p)[i+1]}
}