// choose calculates the binomial coefficient C(n,k) aka nCk
191920
func choose(n, k int) int {
	if k == 0 {
		return 1
	} else if n == 0 {
		return 0
	}
	result := float32(n - (k - 1))
	for i := 2; i <= k; i++ {
		result *= float32(n-(k-i)) / float32(i)
	}

	return int(result)
}
300111
func (s *SelectQuery) SelectOption(option string) *SelectQuery {
	s.selectOption = option
	return s
}
1373187
func (t *Object) Select(name interface{}) Type {
	for _, p := range t.static {
		if util.Compare(p.Key, name) == 0 {
			return p.Value
		}
	}
	if t.dynamic != nil {
		if Contains(t.dynamic.Key, TypeOf(name)) {
			return t.dynamic.Value
		}
	}
	return nil
}
342195
func (t *Table) Select(row, column int) *Table {
	t.selectedRow, t.selectedColumn = row, column
	return t
}
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
}
134455
func (l *List) Select(i int) {
	l.SetSelected(i)
	if l.onSelectionChanged != nil {
		l.onSelectionChanged(l)
	}
}
877982
func Choose(message string, choices []string, defaultChoice string) string {
	return (&Prompter{
		Message: message,
		Choices: choices,
		Default: defaultChoice,
	}).Prompt()
}
847914
func chooseParameterFormatCode(ci *pgtype.ConnInfo, oid pgtype.OID, arg interface{}) int16 {
	switch arg.(type) {
	case pgtype.BinaryEncoder:
		return BinaryFormatCode
	case string, *string, pgtype.TextEncoder:
		return TextFormatCode
	}

	if dt, ok := ci.DataTypeForOID(oid); ok {
		if _, ok := dt.Value.(pgtype.BinaryEncoder); ok {
			return BinaryFormatCode
		}
	}

	return TextFormatCode
}
1004080
func (d *Device) Option(opts ...Option) error {
	var err error
	for _, opt := range opts {
		err = opt(d)
	}
	return err
}
606393
func (e *Encoding) Option(opts ...option) *Encoding {
	for _, opt := range opts {
		opt(e)
	}

	// Return the encoding to allow chaining
	return e
}
202394
func (d *Dataset) Select(name string, sortOption *SortOption) *Dataset {
	ret, step := add1ShardTo1Step(d)
	indexes := sortOption.Indexes()
	step.SetInstruction(name, instruction.NewSelect([]int{indexes[0]}, indexes[1:]))
	step.Description = fmt.Sprintf("select %v", sortOption.Indexes())
	return ret
}
188141
func (c *Menu) SelectNextOption() {
	idx := c.GetSelectedIndex()
	for idx < len(c.options) {
		idx++
		testOption := c.GetOptionFromIndex(idx)
		if testOption != nil && !testOption.IsDisabled() {
			c.SetSelectedOption(testOption)
			return
		}
	}
}
346995
func (r *charRange) choose(rand *rand.Rand) rune {
	count := int64(r.last - r.first)
	return r.first + rune(rand.Int63n(count))
}
1014287
func (b *Base) Pick(keys ...string) Serializer {
	return b.PickFunc(identity, keys...)
}
56783
func (p *Pollster) Select(l List) (string, error) {
	return p.SelectVerify(l, VerifyOptions(l.Singular, l.Options, l.Default != ""))
}
487125
func (r *Pool) Pick() NumberGenerator {
	// use round robin with fast modulus of pow2 numbers
	selection := atomic.AddUint64(&r.counter, 1) & (r.size - 1)
	return r.sources[selection]
}
241202
func chooseN(n uint32, s map[NodeID]*NodeScore) (
	map[NodeID]*NodeScore, error) {

	// Keep track of the number of nodes not yet chosen, in addition to
	// their scores and NodeIDs.
	rem := len(s)
	scores := make([]float64, len(s))
	nodeIDs := make([]NodeID, len(s))
	i := 0
	for k, v := range s {
		scores[i] = v.Score
		nodeIDs[i] = k
		i++
	}

	// Pick a weighted choice from the remaining nodes as long as there are
	// nodes left, and we haven't already picked n.
	chosen := make(map[NodeID]*NodeScore)
	for len(chosen) < int(n) && rem > 0 {
		choice, err := weightedChoice(scores)
		if err == ErrNoPositive {
			return chosen, nil
		} else if err != nil {
			return nil, err
		}

		nID := nodeIDs[choice]

		chosen[nID] = s[nID]

		// We set the score of the chosen node to 0, so it won't be
		// picked the next iteration.
		scores[choice] = 0
	}

	return chosen, nil
}