// SortedExplainExpressionList generates explain information for a list of expressions in order.
// In some scenarios, the expr's order may not be stable when executing multiple times.
// So we add a sort to make its explain result stable.
425274
func SortedExplainExpressionList(exprs []Expression) []byte {
	buffer := bytes.NewBufferString("")
	exprInfos := make([]string, 0, len(exprs))
	for _, expr := range exprs {
		exprInfos = append(exprInfos, expr.ExplainInfo())
	}
	sort.Strings(exprInfos)
	for i, info := range exprInfos {
		buffer.WriteString(info)
		if i+1 < len(exprInfos) {
			buffer.WriteString(", ")
		}
	}
	return buffer.Bytes()
}
1212893
func (n *Namespaces) PrefixList(prefix string, q *QueryOptions) ([]*Namespace, *QueryMeta, error) {
	if q == nil {
		q = &QueryOptions{Prefix: prefix}
	} else {
		q.Prefix = prefix
	}

	return n.List(q)
}
982280
func ExtractExplain(opts ...interface{}) *opt.ExplainOption {
	for _, o := range opts {
		if v, ok := o.(*opt.ExplainOption); ok {
			return v
		}
	}
	return nil
}
454145
func (me *DefaultAdapter) OrderedExpressionSql(buf *SqlBuilder, order OrderedExpression) error {
	if err := me.Literal(buf, order.SortExpression()); err != nil {
		return err
	}
	if order.Direction() == SORT_DESC {
		buf.Write(me.DescFragment)
	} else {
		buf.Write(me.AscFragment)
	}
	switch order.NullSortType() {
	case NULLS_FIRST:
		buf.Write(me.NullsFirstFragment)
	case NULLS_LAST:
		buf.Write(me.NullsLastFragment)
	}
	return nil
}
391783
func (o *L2DomainTemplate) PGExpressionTemplates(info *bambou.FetchingInfo) (PGExpressionTemplatesList, *bambou.Error) {

	var list PGExpressionTemplatesList
	err := bambou.CurrentSession().FetchChildren(o, PGExpressionTemplateIdentity, &list, info)
	return list, err
}
991897
func (s String) UnsortedList() []string {
	res := make([]string, 0, len(s))
	for key := range s {
		res = append(res, key)
	}
	return res
}
893708
func (e *Evaluations) List(q *QueryOptions) ([]*Evaluation, *QueryMeta, error) {
	var resp []*Evaluation
	qm, err := e.client.query("/v1/evaluations", &resp, q)
	if err != nil {
		return nil, nil, err
	}
	sort.Sort(EvalIndexSort(resp))
	return resp, qm, nil
}
1351644
func (en exprNode) buildExpressionString(aliasList *aliasList) (string, error) {
	// Since each exprNode contains a slice of names, values, and children that
	// correspond to the escaped characters, we an index to traverse the slices
	index := struct {
		name, value, children int
	}{}

	formattedExpression := en.fmtExpr

	for i := 0; i < len(formattedExpression); {
		if formattedExpression[i] != '$' {
			i++
			continue
		}

		if i == len(formattedExpression)-1 {
			return "", fmt.Errorf("buildexprNode error: invalid escape character")
		}

		var alias string
		var err error
		// if an escaped character is found, substitute it with the proper alias
		// TODO consider AST instead of string in the future
		switch formattedExpression[i+1] {
		case 'n':
			alias, err = substitutePath(index.name, en, aliasList)
			if err != nil {
				return "", err
			}
			index.name++

		case 'v':
			alias, err = substituteValue(index.value, en, aliasList)
			if err != nil {
				return "", err
			}
			index.value++

		case 'c':
			alias, err = substituteChild(index.children, en, aliasList)
			if err != nil {
				return "", err
			}
			index.children++

		default:
			return "", fmt.Errorf("buildexprNode error: invalid escape rune %#v", formattedExpression[i+1])
		}
		formattedExpression = formattedExpression[:i] + alias + formattedExpression[i+2:]
		i += len(alias)
	}

	return formattedExpression, nil
}
320834
func (f *ConstraintFilter) Explain(nodes int) string {
	if nodes == 1 {
		return "scheduling constraints not satisfied on 1 node"
	}
	return fmt.Sprintf("scheduling constraints not satisfied on %d nodes", nodes)
}
317579
func (p *parser) parseAdditiveExpr(n node) node {
	opnd := p.parseMultiplicativeExpr(n)
Loop:
	for {
		var op string
		switch p.r.typ {
		case itemPlus:
			op = "+"
		case itemMinus:
			op = "-"
		default:
			break Loop
		}
		p.next()
		opnd = newOperatorNode(op, opnd, p.parseMultiplicativeExpr(n))
	}
	return opnd
}
642046
func SortExtensions(m map[string]Extension) ([]Extension, error) {
	pMap := make(map[int]Extension)
	priorities := make([]int, 0, len(m))
	for n, ext := range m {
		p := ext.Priority
		if _, exist := pMap[p]; exist {
			err := fmt.Errorf("duplicate priority %d on %s", p, n)
			return nil, err
		}
		pMap[p] = ext
		priorities = append(priorities, p)
	}

	sort.Ints(priorities)

	result := make([]Extension, len(priorities))
	for i, p := range priorities {
		result[i] = pMap[p]
	}

	return result, nil
}
683481
func ReferencesInExpr(expr hcl.Expression) ([]*addrs.Reference, tfdiags.Diagnostics) {
	if expr == nil {
		return nil, nil
	}
	traversals := expr.Variables()
	return References(traversals)
}
973230
func (b *Builtin) Expr(operands ...*Term) *Expr {
	ts := make([]*Term, len(operands)+1)
	ts[0] = NewTerm(b.Ref())
	for i := range operands {
		ts[i+1] = operands[i]
	}
	return &Expr{
		Terms: ts,
	}
}
308306
func SortedPrefixes(p *Properties, prefixes []string) []Prefix {
	/*
	   With properties for:
	   {
	   	line-width: 2;
	   	top/line-width: 1;
	   	polygon-fill: red;
	   }

	   SortedPrefixes(p, []string{"line-", "polygon-"})
	   will return
	   []Prefix{{"line-", ""}, {"line-", "top"}, {"polygon-", ""}}

	*/
	pp := make([]prefixPos, 0, len(prefixes))
	for _, prefix := range prefixes {
		pos := p.minPrefixPos(prefix)
		pp = append(pp, pos...)
	}
	sort.Sort(byIndex(pp))

	result := make([]Prefix, len(pp))
	for i, p := range pp {
		result[i] = Prefix{Name: p.prefix, Instance: p.instance}
	}
	return result
}
1257297
func httpListExtContractsGroups(w http.ResponseWriter, r *http.Request, vars map[string]string) (interface{}, error) {
	log.Debugf("Received httpListExtContractsGroups: %+v", vars)

	list := make([]*ExtContractsGroup, 0)
	collections.extContractsGroupMutex.Lock()
	defer collections.extContractsGroupMutex.Unlock()
	for _, obj := range collections.extContractsGroups {
		list = append(list, obj)
	}

	// Return the list
	return list, nil
}
674805
func SortAlphabeticFunc(list []string) func(i, j int) bool {
	return func(i, j int) bool {
		return LessIgnoreCase(list[i], list[j])
	}
}
1187680
func matchEqExpr(expr syntax.Expr) (lhs string, rhs syntax.Expr) {
	bin, ok := expr.(*syntax.BinaryExpr)
	if !ok || bin.Op != syntax.EQ {
		return "", nil
	}
	if lhs = matchSingleIdent(bin.X); lhs == "" {
		return "", nil
	}
	return lhs, bin.Y
}