// Connect connects g1 and g2 by making v1 in g1 a common vertex
// with 0 in g2. The vertices in g2 are renumbered: 0 becomes v1
// in the new graph; and w, with w > 0, becomes w + g1.Order() - 1.
//
963627
func (g1 *Virtual) Connect(v1 int, g2 *Virtual) *Virtual {
	if g1.order == 0 || g2.order == 0 || v1 < 0 || v1 >= g1.order {
		return nil
	}

	n := g1.order + g2.order - 1
	t := g1.order - 1 // transpose
	if n == 1 {
		return singleton()
	}

	newCost := func(v, w int) int64 {
		switch {
		case v <= t && w <= t:
			return g1.cost(v, w)
		case v > t && w > t:
			return g2.cost(v-t, w-t)
		case v == v1:
			return g2.cost(0, w-t)
		case w == v1:
			return g2.cost(v-t, 0)
		default:
			return 0
		}
	}

	res := generic(n, newCost, func(v, w int) bool {
		switch {
		case v <= t && w <= t:
			return g1.edge(v, w)
		case v > t && w > t:
			return g2.edge(v-t, w-t)
		case v == v1:
			return g2.edge(0, w-t)
		case w == v1:
			return g2.edge(v-t, 0)
		default:
			return false
		}
	})

	res.degree = func(v int) (deg int) {
		switch {
		case v == v1:
			return g1.degree(v) + g2.degree(0)
		case v <= t:
			return g1.degree(v)
		default:
			return g2.degree(v - t)
		}
	}

	res.visit = func(v int, a int, do func(w int, c int64) bool) (aborted bool) {
		switch {
		case v > t:
			return g2.visit(v-t, max(0, a-t), func(w int, c int64) (skip bool) {
				if w == 0 {
					return v1 >= a && do(v1, c)
				}
				return do(w+t, c)
			})
		case g1.visit(v, a, do):
			return true
		case v == v1:
			return g2.visit(0, max(0, a-t), func(w int, c int64) (skip bool) {
				return do(w+t, c)
			})
		default:
			return
		}
	}
	return res
}
1067666
func (graphite *Graphite) Connect() error {
	if !graphite.IsNop() {
		if graphite.conn != nil {
			graphite.conn.Close()
		}

		address := fmt.Sprintf("%s:%d", graphite.Host, graphite.Port)

		if graphite.Timeout == 0 {
			graphite.Timeout = defaultTimeout * time.Second
		}

		var err error
		var conn net.Conn

		if graphite.Protocol == "udp" {
			udpAddr, err := net.ResolveUDPAddr("udp", address)
			if err != nil {
				return err
			}
			conn, err = net.DialUDP(graphite.Protocol, nil, udpAddr)
		} else {
			conn, err = net.DialTimeout(graphite.Protocol, address, graphite.Timeout)
		}

		if err != nil {
			return err
		}

		graphite.conn = conn
	}

	return nil
}
302864
func (c *Client) Connect(ctx context.Context, src *chronograf.Source) error {
	span, _ := tracing.StartSpanFromContext(ctx)
	defer span.Finish()

	u, err := url.Parse(src.URL)
	if err != nil {
		return err
	}
	c.Authorizer = DefaultAuthorization(src)
	// Only allow acceptance of all certs if the scheme is https AND the user opted into to the setting.
	if u.Scheme == "https" && src.InsecureSkipVerify {
		c.InsecureSkipVerify = src.InsecureSkipVerify
	}

	c.URL = u
	return nil
}
371981
func (l *Adaptor) Connect() (err error) {
	ws, e := l.connect(l.Port())
	if e != nil {
		return e
	}

	l.ws = ws
	return
}
163013
func (e *Adaptor) Connect() (err error) {
	e.mutex.Lock()
	defer e.mutex.Unlock()

	e.digitalPins = make(map[int]*sysfs.DigitalPin)
	e.pwmPins = make(map[int]*sysfs.PWMPin)
	err = e.connect(e)
	return
}
381744
func (w *Wallet) connect() error {
	w.lock.Lock()
	defer w.lock.Unlock()

	appinfo, err := w.doselect()
	if err != nil {
		return err
	}

	channel, err := NewSecureChannelSession(w.card, appinfo.PublicKey)
	if err != nil {
		return err
	}

	w.PublicKey = appinfo.PublicKey
	w.log = log.New("url", w.URL())
	w.session = &Session{
		Wallet:  w,
		Channel: channel,
	}
	return nil
}
729957
func (s *Session) connect(host *HostInfo, errorHandler ConnErrorHandler) (*Conn, error) {
	return s.dial(host, s.connCfg, errorHandler)
}
287382
func (w *Writer) connect() (err error) {
	if w.conn != nil {
		// ignore err from close, it makes sense to continue anyway
		w.conn.close()
		w.conn = nil
	}

	var c net.Conn
	c, err = net.Dial(w.network, w.raddr)
	if err == nil {
		w.conn = &netConn{conn: c}
		if w.hostname == "" {
			w.hostname = c.LocalAddr().String()
		}
	}
	return
}
78830
func (c *Conn) Connect() error {
	ret := C.rados_connect(c.cluster)
	if ret != 0 {
		return RadosError(int(ret))
	}
	c.connected = true
	return nil
}
1165927
func (r *AttachREST) Connect(ctx context.Context, name string, opts runtime.Object, responder rest.Responder) (http.Handler, error) {
	attachOpts, ok := opts.(*api.PodAttachOptions)
	if !ok {
		return nil, fmt.Errorf("Invalid options object: %#v", opts)
	}
	location, transport, err := pod.AttachLocation(r.Store, r.KubeletConn, ctx, name, attachOpts)
	if err != nil {
		return nil, err
	}
	return newThrottledUpgradeAwareProxyHandler(location, transport, false, true, true, responder), nil
}
1370653
func (d *Driver) connect(ctx context.Context, c *Connector, params connectParams) (*Conn, error) {
	sess, err := connect(ctx, c, d.log, params)
	if err != nil {
		// main server failed, try fail-over partner
		if params.failOverPartner == "" {
			return nil, err
		}

		params.host = params.failOverPartner
		if params.failOverPort != 0 {
			params.port = params.failOverPort
		}

		sess, err = connect(ctx, c, d.log, params)
		if err != nil {
			// fail-over partner also failed, now fail
			return nil, err
		}
	}

	conn := &Conn{
		connector:        c,
		sess:             sess,
		transactionCtx:   context.Background(),
		processQueryText: d.processQueryText,
		connectionGood:   true,
	}
	conn.sess.log = d.log

	return conn, nil
}
709423
func (r *PortForwardREST) Connect(ctx context.Context, name string, opts runtime.Object, responder rest.Responder) (http.Handler, error) {
	portForwardOpts, ok := opts.(*api.PodPortForwardOptions)
	if !ok {
		return nil, fmt.Errorf("invalid options object: %#v", opts)
	}
	location, transport, err := pod.PortForwardLocation(r.Store, r.KubeletConn, ctx, name, portForwardOpts)
	if err != nil {
		return nil, err
	}
	return newThrottledUpgradeAwareProxyHandler(location, transport, false, true, true, responder), nil
}
631388
func (d *HypervPS4Driver) Connect(vmName string) (context.CancelFunc, error) {
	return hyperv.ConnectVirtualMachine(vmName)
}
456898
func (m *Adaptor) Connect() (err error) {
	if sp, e := m.connect(m.Port()); e != nil {
		return e
	} else {
		m.sp = sp
	}
	return
}
1042634
func (c *Client) Connect() (client.Session, error) {
	if c.file == nil {
		if err := c.initFile(); err != nil {
			return nil, err
		}
	}
	return &Session{c.file}, nil
}
1013297
func (f *Fibre) Connect(p string, h HandlerFunc) {
	f.router.Add(CONNECT, p, h)
}
407632
func (pc poolConnector) Connect(ctx context.Context) (driver.Conn, error) {
	var (
		err  error
		conn *pgx.Conn
	)

	if conn, err = pc.pool.Acquire(); err != nil {
		return nil, err
	}

	return &Conn{conn: conn, driver: pc.driver, connConfig: pgx.ConnConfig{PreferSimpleProtocol: pc.preferSimpleProtocol}}, nil
}