// CoinSelect will attempt to select coins using the algorithm described
// in the MinIndexCoinSelector struct.
776362
func (s MinIndexCoinSelector) CoinSelect(targetValue btcutil.Amount, coins []Coin) (Coins, error) {
	cs := NewCoinSet(nil)
	for n := 0; n < len(coins) && n < s.MaxInputs; n++ {
		cs.PushCoin(coins[n])
		if satisfiesTargetValue(targetValue, s.MinChangeAmount, cs.TotalValue()) {
			return cs, nil
		}
	}
	return nil, ErrCoinsNoSelectionAvailable
}
80867
func (s *Selection) HasSelection(sel *Selection) *Selection {
	if sel == nil {
		return s.HasNodes()
	}
	return s.HasNodes(sel.Nodes...)
}
721060
func (o ListOptions) GetTotalAndSelected() (total, selected uint64) {
	return o.total, o.selected
}
147232
func (s *Selection) AppendSelection(sel *Selection) *Selection {
	return s.AppendNodes(sel.Nodes...)
}
107167
func coinSelect(feeRate SatPerKWeight, amt btcutil.Amount,
	coins []*Utxo) ([]*Utxo, btcutil.Amount, error) {

	amtNeeded := amt
	for {
		// First perform an initial round of coin selection to estimate
		// the required fee.
		totalSat, selectedUtxos, err := selectInputs(amtNeeded, coins)
		if err != nil {
			return nil, 0, err
		}

		var weightEstimate input.TxWeightEstimator

		for _, utxo := range selectedUtxos {
			switch utxo.AddressType {
			case WitnessPubKey:
				weightEstimate.AddP2WKHInput()
			case NestedWitnessPubKey:
				weightEstimate.AddNestedP2WKHInput()
			default:
				return nil, 0, fmt.Errorf("Unsupported address type: %v",
					utxo.AddressType)
			}
		}

		// Channel funding multisig output is P2WSH.
		weightEstimate.AddP2WSHOutput()

		// Assume that change output is a P2WKH output.
		//
		// TODO: Handle wallets that generate non-witness change
		// addresses.
		weightEstimate.AddP2WKHOutput()

		// The difference between the selected amount and the amount
		// requested will be used to pay fees, and generate a change
		// output with the remaining.
		overShootAmt := totalSat - amt

		// Based on the estimated size and fee rate, if the excess
		// amount isn't enough to pay fees, then increase the requested
		// coin amount by the estimate required fee, performing another
		// round of coin selection.
		totalWeight := int64(weightEstimate.Weight())
		requiredFee := feeRate.FeeForWeight(totalWeight)
		if overShootAmt < requiredFee {
			amtNeeded = amt + requiredFee
			continue
		}

		// If the fee is sufficient, then calculate the size of the
		// change output.
		changeAmt := overShootAmt - requiredFee

		return selectedUtxos, changeAmt, nil
	}
}
625620
func SpiChipSelect(chip uint8) {
	const csMask = 3 // chip select has 2 bits

	cs := uint32(chip & csMask)

	spiMem[csReg] = spiMem[csReg]&^csMask | cs
}
201749
func StringQuickSelect(data []string, k int) error {
	return QuickSelect(StringSlice(data), k)
}
451042
func Select(ctx context.Context, sctx sessionctx.Context, kvReq *kv.Request, fieldTypes []*types.FieldType, fb *statistics.QueryFeedback) (SelectResult, error) {
	// For testing purpose.
	if hook := ctx.Value("CheckSelectRequestHook"); hook != nil {
		hook.(func(*kv.Request))(kvReq)
	}

	if !sctx.GetSessionVars().EnableStreaming {
		kvReq.Streaming = false
	}
	resp := sctx.GetClient().Send(ctx, kvReq, sctx.GetSessionVars().KVVars)
	if resp == nil {
		err := errors.New("client returns nil response")
		return nil, err
	}

	// kvReq.MemTracker is used to trace and control memory usage in DistSQL layer;
	// for streamResult, since it is a pipeline which has no buffer, it's not necessary to trace it;
	// for selectResult, we just use the kvReq.MemTracker prepared for co-processor
	// instead of creating a new one for simplification.
	if kvReq.Streaming {
		return &streamResult{
			resp:       resp,
			rowLen:     len(fieldTypes),
			fieldTypes: fieldTypes,
			ctx:        sctx,
			feedback:   fb,
		}, nil
	}

	label := metrics.LblGeneral
	if sctx.GetSessionVars().InRestrictedSQL {
		label = metrics.LblInternal
	}
	return &selectResult{
		label:      "dag",
		resp:       resp,
		results:    make(chan resultWithErr, kvReq.Concurrency),
		closed:     make(chan struct{}),
		rowLen:     len(fieldTypes),
		fieldTypes: fieldTypes,
		ctx:        sctx,
		feedback:   fb,
		sqlType:    label,
		memTracker: kvReq.MemTracker,
	}, nil
}
988085
func ParseSelectorOrDie(s string) Selector {
	selector, err := ParseSelector(s)
	if err != nil {
		panic(err)
	}
	return selector
}
617279
func Select(root NodeNavigator, expr string) *NodeIterator {
	exp, err := Compile(expr)
	if err != nil {
		panic(err)
	}
	return exp.Select(root)
}
355139
func (c *SimpleCoin) txOut() *wire.TxOut {
	return c.Tx.MsgTx().TxOut[c.TxIndex]
}
766175
func (tx *Tx) Select(column ...string) *SelectStmt {
	b := Select(prepareSelect(column)...)
	b.runner = tx
	b.EventReceiver = tx.EventReceiver
	b.Dialect = tx.Dialect
	return b
}
1106014
func GetSelection(ctx context.Context, prompt, usage string, choices []string) (string, int) {
	if tw := os.Getenv("GOPASS_CUI_TERMWIZ"); tw != "" || runtime.GOOS == "openbsd" {
		return termwiz.GetSelection(ctx, prompt, usage, choices)
	}
	if ctxutil.IsAlwaysYes(ctx) || !ctxutil.IsInteractive(ctx) {
		return "impossible", 0
	}
	g, err := gocui.NewGui(gocui.OutputNormal)
	if err != nil {
		panic(err)
	}
	defer g.Close()

	g.InputEsc = true
	g.Mouse = false
	g.Cursor = false
	if runtime.GOOS == "windows" {
		g.ASCII = true
	}

	s := selection{
		prompt:    prompt,
		usage:     usage,
		choices:   choices,
		action:    "",
		selection: 0,
	}

	g.SetManagerFunc(s.layout)

	if err := s.keybindings(g); err != nil {
		panic(err)
	}

	if err := g.MainLoop(); err != nil {
		if err != gocui.ErrQuit {
			return "aborted", s.selection
		}
	}
	return s.action, s.selection
}
134455
func (l *List) Select(i int) {
	l.SetSelected(i)
	if l.onSelectionChanged != nil {
		l.onSelectionChanged(l)
	}
}
384349
func (u *Ugen) Coin() Input {
	return unaryOpCoin(u.Rate, u, u.NumOutputs)
}
629557
func (s *Selection) NextMatcherUntilSelection(filter Matcher, sel *Selection) *Selection {
	if sel == nil {
		return s.NextMatcher(filter)
	}
	return s.NextMatcherUntilNodes(filter, sel.Nodes...)
}
1157641
func (p *Pool) selectNode(selected nodeList) (Node, error) {

	defer scopedLock(&p.mutx)()

	if len(p.nodes) == 0 {
		return Node{}, errors.New("disque: no nodes in pool")
	}

	nodes := nodeList{}
	for _, node := range p.nodes {
		if node.Priority <= maxPriority && !selected.contains(node) {
			nodes = append(nodes, node)
		}
	}
	if len(nodes) == 0 {
		return Node{}, errors.New("disque: no nodes left to select from")
	}

	return nodes[rand.Intn(len(nodes))], nil

}