// FindPrefixOfIndex will find columns in index by checking the unique id.
// So it will return at once no matching column is found.
764006
func FindPrefixOfIndex(cols []*Column, idxColIDs []int64) []*Column {
	retCols := make([]*Column, 0, len(idxColIDs))
idLoop:
	for _, id := range idxColIDs {
		for _, col := range cols {
			if col.UniqueID == id {
				retCols = append(retCols, col)
				continue idLoop
			}
		}
		// If no matching column is found, just return.
		return retCols
	}
	return retCols
}
732452
func (h *Helper) FindTableIndexOfRegion(allSchemas []*model.DBInfo, hotRange *RegionFrameRange) *FrameItem {
	for _, db := range allSchemas {
		for _, tbl := range db.Tables {
			if f := hotRange.GetRecordFrame(tbl.ID, db.Name.O, tbl.Name.O); f != nil {
				return f
			}
			for _, idx := range tbl.Indices {
				if f := hotRange.GetIndexFrame(tbl.ID, idx.ID, db.Name.O, tbl.Name.O, idx.Name.O); f != nil {
					return f
				}
			}
		}
	}
	return nil
}
479893
func getSubPrefix(curPrefix, subField string) string {
	if curPrefix != "" {
		return fmt.Sprintf("%s.%s", curPrefix, subField)
	}
	return fmt.Sprintf("%s", subField)
}
726410
func areColumnsAPrefixOfAnIndex(columns []*schema.TableColumn, table *schema.Table) bool {
	for _, index := range table.Indexes {
		if areColumnsAPrefixOfIndex(columns, index) {
			return true
		}
	}
	return false
}
1056249
func ExtractIndexName(opts ...interface{}) *opt.IndexNameOption {
	for _, o := range opts {
		if v, ok := o.(*opt.IndexNameOption); ok {
			return v
		}
	}
	return nil
}
906104
func findExistingPrefix(base, pathname string) (string, []string, error) {
	rel, err := filepath.Rel(base, pathname)
	if err != nil {
		return base, nil, err
	}

	if mount.StartsWithBackstep(rel) {
		return base, nil, fmt.Errorf("pathname(%s) is not within base(%s)", pathname, base)
	}

	if rel == "." {
		// base and pathname are equal
		return pathname, []string{}, nil
	}

	dirs := strings.Split(rel, string(filepath.Separator))

	parent := base
	currentPath := base
	for i, dir := range dirs {
		parent = currentPath
		currentPath = filepath.Join(parent, dir)
		if _, err := os.Lstat(currentPath); err != nil {
			if os.IsNotExist(err) {
				return parent, dirs[i:], nil
			}
			return base, nil, err
		}
	}

	return pathname, []string{}, nil
}
259903
func (r *readerOffsets) searchPrefix(n int) int {
	i, j := 0, len(r.prefixes)
	for i < j {
		h := int(uint(i+j) >> 1)
		if n >= r.prefixes[h].total {
			i = h + 1
		} else {
			j = h
		}
	}
	return i
}
351670
func (c *Client) GetFrameworkByPrefix(frameworks []Framework, prefix string) (*Framework, error) {
	for _, framework := range frameworks {
		if strings.HasPrefix(framework.Name, prefix) {
			return &framework, nil
		}
	}

	return nil, fmt.Errorf("Framework with prefix \"%s\" not found", prefix)
}
1139003
func findExistingPrefix(base, pathname string) (string, []string, error) {
	rel, err := filepath.Rel(base, pathname)
	if err != nil {
		return base, nil, err
	}
	dirs := strings.Split(rel, string(filepath.Separator))

	// Do OpenAt in a loop to find the first non-existing dir. Resolve symlinks.
	// This should be faster than looping through all dirs and calling os.Stat()
	// on each of them, as the symlinks are resolved only once with OpenAt().
	currentPath := base
	fd, err := syscall.Open(currentPath, syscall.O_RDONLY, 0)
	if err != nil {
		return pathname, nil, fmt.Errorf("error opening %s: %s", currentPath, err)
	}
	defer func() {
		if err = syscall.Close(fd); err != nil {
			klog.V(4).Infof("Closing FD %v failed for findExistingPrefix(%v): %v", fd, pathname, err)
		}
	}()
	for i, dir := range dirs {
		// Using O_PATH here will prevent hangs in case user replaces directory with
		// fifo
		childFD, err := syscall.Openat(fd, dir, unix.O_PATH, 0)
		if err != nil {
			if os.IsNotExist(err) {
				return currentPath, dirs[i:], nil
			}
			return base, nil, err
		}
		if err = syscall.Close(fd); err != nil {
			klog.V(4).Infof("Closing FD %v failed for findExistingPrefix(%v): %v", fd, pathname, err)
		}
		fd = childFD
		currentPath = filepath.Join(currentPath, dir)
	}
	return pathname, []string{}, nil
}
572734
func (db *DB) schemaIndexPrefix(name string) (id byte, err error) {
	if name == "" {
		return 0, errors.New("index name can not be blank")
	}
	s, err := db.getSchema()
	if err != nil {
		return 0, err
	}
	nextID := keyPrefixIndexStart
	for i, f := range s.Indexes {
		if i >= nextID {
			nextID = i + 1
		}
		if f.Name == name {
			return i, nil
		}
	}
	id = nextID
	s.Indexes[id] = indexSpec{
		Name: name,
	}
	return id, db.putSchema(s)
}
1357799
func ParsePrefix(raw string) (p *Prefix) {

	p = new(Prefix)

	user := indexByte(raw, prefixUser)
	host := indexByte(raw, prefixHost)

	switch {

	case user > 0 && host > user:
		p.Name = raw[:user]
		p.User = raw[user+1 : host]
		p.Host = raw[host+1:]

	case user > 0:
		p.Name = raw[:user]
		p.User = raw[user+1:]

	case host > 0:
		p.Name = raw[:host]
		p.Host = raw[host+1:]

	default:
		p.Name = raw

	}

	return p
}
949871
func (ei *EntityInfo) IndexFromConditions(conditions map[string][]*Condition, searchIndexes bool) (name string, key *PrimaryKey, err error) {
	identityFunc := func(s string) string { return s }
	// see if we match the primary key for this table
	var baseTableError error
	if baseTableError = EnsureValidRangeConditions(ei.Def, ei.Def.Key, conditions, identityFunc); baseTableError == nil {
		return ei.Def.Name, ei.Def.Key, nil
	}
	if searchIndexes == false || len(ei.Def.Indexes) == 0 {
		return "", nil, baseTableError
	}
	// see if we match an index on this table
	var indexDef *IndexDefinition
	for name, indexDef = range ei.Def.Indexes {
		key = indexDef.Key
		// we check the range conditions before adding the uniqueness columns
		if err := EnsureValidRangeConditions(ei.Def, key, conditions, identityFunc); err == nil {
			return name, ei.Def.UniqueKey(key), nil
		}
	}
	// none of the indexes work, so fail
	return "", nil, errors.Wrapf(baseTableError, "No index matches specified conditions")
}
848741
func parsePrefix(req *http.Request, b *structs.QueryOptions) {
	query := req.URL.Query()
	if prefix := query.Get("prefix"); prefix != "" {
		b.Prefix = prefix
	}
}
835288
func comparePrefix(a, b prefix) int {
	au, bu := binary.BigEndian.Uint64(a[:8]), binary.BigEndian.Uint64(b[:8])
	if au == bu {
		return 0
	} else if au < bu {
		return -1
	}
	return 1
}
472568
func (p Path) HasPrefix(other Path) bool {
	if len(other) > len(p) {
		return false
	}
	for i := range other {
		if p[i] != other[i] {
			return false
		}
	}
	return true
}
1218367
func (d DoubleArray) CommonPrefixSearch(input string) (ids, lens []int) {
	var p, q int
	bufLen := len(d)
	for i, size := 0, len(input); i < size; i++ {
		if input[i] == terminator {
			return
		}
		p = q
		q = int(d[p].Base) + int(input[i])
		if q >= bufLen || int(d[q].Check) != p {
			break
		}
		ahead := int(d[q].Base) + int(terminator)
		if ahead < bufLen && int(d[ahead].Check) == q && int(d[ahead].Base) <= 0 {
			ids = append(ids, int(-d[ahead].Base))
			lens = append(lens, i+1)
		}
	}
	return
}
563856
func (h hashPrefix) HasPrefix(other hashPrefix) bool {
	return strings.HasPrefix(string(h), string(other))
}