// Precedence returns the operator precedence of the binary
// operator op. If op is not a binary operator, the result
// is LowestPrecedence.
//
422683
func (op Token) Precedence() int {
	switch op {
	case LOR:
		return 1
	case LAND:
		return 2
	case EQL, NEQ, LSS, LEQ, GTR, GEQ:
		return 3
	case ADD, SUB, OR, XOR:
		return 4
	case MUL, QUO, REM, SHL, SHR, AND, AND_NOT:
		return 5
	}
	return LowestPrec
}
1123875
func (a *CompositeAggregationTermsValuesSource) Order(order string) *CompositeAggregationTermsValuesSource {
	a.order = order
	return a
}
725200
func (p *Printer) Priority(prio int) *Printer {
	p.mu.Lock()
	p.priority = prio
	p.mu.Unlock()
	return p
}
830226
func (x Vector) Order() Vector {
	y := x.Copy()
	y.Sort()

	rank := 0
	order := make(Vector, len(x))
	for i, _ := range order {
		order[i] = -1
	}
	for i, _ := range y {
		for j, _ := range x {
			if y[i] == x[j] && order[j] == -1 {
				order[j] = float64(rank)
				rank++
				break
			}
		}
	}
	return order
}
1145656
func InOrder(calls ...*Call) {
	for i := 1; i < len(calls); i++ {
		calls[i].After(calls[i-1])
	}
}
337791
func MinProximityEqual(o1, o2 *MinProximityOption) bool {
	if o1 != nil {
		return o1.Equal(o2)
	}
	if o2 != nil {
		return o2.Equal(o1)
	}
	return true
}
207261
func (o *TypeOption) Equal(o2 *TypeOption) bool {
	if o2 == nil {
		return o.value == ""
	}
	return o.value == o2.value
}
140963
func TopSort(g Iterator) (order []int, ok bool) {
	order, ok = topsort(g, true)
	return
}
450010
func (expr *Expr) Operator() Ref {
	terms, ok := expr.Terms.([]*Term)
	if !ok || len(terms) == 0 {
		return nil
	}
	return terms[0].Value.(Ref)
}
656260
func order(r rune) int {
	// all the letters sort earlier than all the non-letters
	if unicode.IsLetter(r) {
		return int(r)
	}

	// a tilde sorts before anything
	if r == '~' {
		return -1
	}

	return int(r) + 256
}
606663
func (a Int32Array) EqualWithoutOrder(b Int32Array) bool {
	if len(a) != len(b) {
		return false
	}

	sort.Sort(a)
	sort.Sort(b)

	for i := range a {
		if a[i] != b[i] {
			return false
		}
	}

	return true
}
1027948
func (r *ThresholdRule) Exclusive() *ThresholdRule {
	if r.operator == greaterEqualThan {
		r.operator = greaterThan
		r.message = fmt.Sprintf("must be greater than %v", r.threshold)
	} else if r.operator == lessEqualThan {
		r.operator = lessThan
		r.message = fmt.Sprintf("must be less than %v", r.threshold)
	}
	return r
}
376467
func (t EnumType) Equal(u convert.Equaler) bool {
	other, ok := u.(EnumType)
	if !ok {
		return false
	}
	if !convert.CascadeEqual(t.SimpleType, other.SimpleType) {
		return false
	}
	if !convert.CascadeEqual(t.BaseType, other.BaseType) {
		return false
	}
	if !t.RewritableValues {
		if !reflect.DeepEqual(t.Values, other.Values) {
			return false
		}
	}
	if !reflect.DeepEqual(t.DefaultValue, other.DefaultValue) {
		return false
	}
	return true
}
1300080
func (x *Intention) UpdatePrecedence() {
	// Max maintains the maximum value that the precedence can be depending
	// on the number of exact values in the destination.
	var max int
	switch x.countExact(x.DestinationNS, x.DestinationName) {
	case 2:
		max = 9
	case 1:
		max = 6
	case 0:
		max = 3
	default:
		// This shouldn't be possible, just set it to zero
		x.Precedence = 0
		return
	}

	// Given the maximum, the exact value is determined based on the
	// number of source exact values.
	countSrc := x.countExact(x.SourceNS, x.SourceName)
	x.Precedence = max - (2 - countSrc)
}
266725
func ParsePriority(buff []byte, cursor *int, l int) (Priority, error) {
	pri := newPriority(0)

	if l <= 0 {
		return pri, ErrPriorityEmpty
	}

	if buff[*cursor] != PRI_PART_START {
		return pri, ErrPriorityNoStart
	}

	i := 1
	priDigit := 0

	for i < l {
		if i >= 5 {
			return pri, ErrPriorityTooLong
		}

		c := buff[i]

		if c == PRI_PART_END {
			if i == 1 {
				return pri, ErrPriorityTooShort
			}

			*cursor = i + 1
			return newPriority(priDigit), nil
		}

		if IsDigit(c) {
			v, e := strconv.Atoi(string(c))
			if e != nil {
				return pri, e
			}

			priDigit = (priDigit * 10) + v
		} else {
			return pri, ErrPriorityNonDigit
		}

		i++
	}

	return pri, ErrPriorityNoEnd
}
437255
func (f Filter) GreaterThanOrEqual(val interface{}) Filter {
	f.Op = ">="
	f.Val = val
	return f
}
1175108
func (p *Parser) parseOperator() (op selection.Operator, err error) {
	tok, lit := p.consume(KeyAndOperator)
	switch tok {
	// DoesNotExistToken shouldn't be here because it's a unary operator, not a binary operator
	case InToken:
		op = selection.In
	case EqualsToken:
		op = selection.Equals
	case DoubleEqualsToken:
		op = selection.DoubleEquals
	case GreaterThanToken:
		op = selection.GreaterThan
	case LessThanToken:
		op = selection.LessThan
	case NotInToken:
		op = selection.NotIn
	case NotEqualsToken:
		op = selection.NotEquals
	default:
		return "", fmt.Errorf("found '%s', expected: '=', '!=', '==', 'in', notin'", lit)
	}
	return op, nil
}