// ClosestN searches for the `searchWord` and returns the n closests matches
322381
func (cm *ClosestMatch) ClosestN(searchWord string, max int) []string {
	matches := make([]string, 0, max)
	for i, pair := range rankByWordCount(cm.match(searchWord)) {
		if i >= max {
			break
		}
		matches = append(matches, pair.Key)
	}
	return matches
}
1097954
func GetN(str, plural string, n int, vars ...interface{}) string {
	return GetND(GetDomain(), str, plural, n, vars...)
}
661233
func MinInt8N(v ...int8) int8 {
	switch len(v) {
	case 0:
		return 0
	case 1:
		return v[0]
	case 2:
		return MinInt8(v[0], v[1])
	default:
		l := len(v) / 2
		return MinInt8N(MinInt8N(v[:l]...), MinInt8N(v[l:]...))
	}
}
941073
func (tab *Table) closest(target enode.ID, nresults int, checklive bool) *nodesByDistance {
	// This is a very wasteful way to find the closest nodes but
	// obviously correct. I believe that tree-based buckets would make
	// this easier to implement efficiently.
	close := &nodesByDistance{target: target}
	for _, b := range &tab.buckets {
		for _, n := range b.entries {
			if checklive && n.livenessChecks == 0 {
				continue
			}
			close.push(n, nresults)
		}
	}
	return close
}
408771
func MaxN(v ...int) int {
	switch len(v) {
	case 0:
		return 0
	case 1:
		return v[0]
	case 2:
		return Max(v[0], v[1])
	default:
		l := len(v) / 2
		return MaxN(MaxN(v[:l]...), MaxN(v[l:]...))
	}
}
632997
func IndexN(str, sep string, n int) (index int) {
	index, idx, sepLen := 0, -1, len(sep)
	for i := 0; i < n; i++ {
		if idx = strings.Index(str, sep); idx == -1 {
			break
		}
		str = str[idx+sepLen:]
		index += idx
	}

	if idx == -1 {
		index = -1
	} else {
		index += (n - 1) * sepLen
	}

	return
}
537766
func listDirsN(dirs []string, N int, root, prefix string) ([]string, error) {
	if N <= 0 {
		return dirs, nil
	}

	allDirs := []string{}
	for _, dir := range dirs {
		files, err := ioutil.ReadDir(path.Join(root, prefix, dir))
		if err != nil {
			return nil, err
		}

		childDirs := []string{}
		for _, f := range files {
			if !f.IsDir() {
				continue
			}

			childDirs = append(childDirs, f.Name())
		}

		nested, err := listDirsN(childDirs, N-1, root, path.Join(prefix, dir))
		if err != nil {
			return nil, err
		}

		for _, n := range nested {
			allDirs = append(allDirs, path.Join(dir, n))
		}
	}

	return allDirs, nil
}
1462
func (c *Call) CloseStream() error {
	if !c.Stream {
		return errors.New("rpc: cannot close non-stream request")
	}
	<-c.sent
	c.client.sending.Lock()
	defer c.client.sending.Unlock()

	c.client.mutex.Lock()
	if c.client.shutdown {
		c.client.mutex.Unlock()
		return ErrShutdown
	}
	c.client.mutex.Unlock()

	c.client.request.ServiceMethod = "CloseStream"
	c.client.request.Seq = c.seq
	return c.client.codec.WriteRequest(&c.client.request, struct{}{})
}
1091517
func (cm *ClosestMatch) Add(possible []string) {
	cm.mux.Lock()
	for i, s := range possible {
		substrings := cm.splitWord(strings.ToLower(s))
		cm.ID[uint32(i)] = IDInfo{Key: s, NumSubstrings: len(substrings)}
		for substring := range substrings {
			if _, ok := cm.SubstringToID[substring]; !ok {
				cm.SubstringToID[substring] = make(map[uint32]struct{})
			}
			cm.SubstringToID[substring][uint32(i)] = struct{}{}
		}
	}
	cm.mux.Unlock()
}
432065
func (store *QueueStore) ListN(n int) []string {
	store.RLock()
	defer store.RUnlock()
	return store.listN(n)
}
1254232
func SetN(n int) Option {
	return func(ngram *NGramIndex) error {
		if n < 2 || n > maxN {
			return errors.New("bad 'n' value for n-gram index")
		}
		ngram.n = n
		return nil
	}
}
999114
func (s *Selection) Closest(selector string) *Selection {
	cs := compileMatcher(selector)
	return s.ClosestMatcher(cs)
}
378732
func (p *parser) peekn(n int) ([]token, error) {
	if len(p.buf) > n {
		return p.buf[:n], nil
	}
	for i := len(p.buf) - 1; i < n; i++ {
		t := p.lexer.token()
		p.buf = append(p.buf, t)
		if t.typ == tokenEOF {
			return p.buf, io.EOF
		}
	}
	return p.buf, nil
}
1053506
func bestn(input string, potential map[string]*Potential, n int) []string {
	var output []string
	for i := 0; i < n; i++ {
		if len(potential) == 0 {
			break
		}
		b := best(input, potential)
		output = append(output, b)
		delete(potential, b)
	}
	return output
}
824273
func NewCloserConn(conn net.Conn, closers ...io.Closer) *CloserConn {
	return &CloserConn{
		Conn:    conn,
		closers: closers,
	}
}
499602
func (r *Rand) Intn(n int) int {
	if n <= 0 {
		panic("invalid argument to Intn")
	}
	if n <= 1<<31-1 {
		return int(r.Int31n(int32(n)))
	}
	return int(r.Int63n(int64(n)))
}
1253944
func CloseScanner() func(Call) error {
	return func(s Call) error {
		scan, ok := s.(*Scan)
		if !ok {
			return errors.New("'Close' option can only be used with Scan queries")
		}
		scan.closeScanner = true
		return nil
	}
}