// alphaCompare compares two alpha version segments and will return a positive
// value if a is bigger than b and a negative if b is bigger than a else 0
190587
func alphaCompare(a, b []rune) int8 {
	if string(a) == string(b) {
		return 0
	}

	i := 0
	for len(a) > i && len(b) > i && a[i] == b[i] {
		i++
	}

	if len(a) == i && len(b) > i {
		return -1
	}

	if len(b) == i {
		return 1
	}

	return int8(a[i]) - int8(b[i])
}
951406
func (s *booleanCompilerVisitor) AcceptComparison(v tree.Comparison) {
	// At this point in the cycle, only EQL, NEQL, GT and GTE are valid comparisons
	if err := compileNumeric(s.ctx, v.Right); err != nil {
		s.err = err
		return
	}

	if err := s.ctx.pushAToStack(); err != nil {
		s.err = err
		return
	}

	if err := compileNumeric(s.ctx, v.Left); err != nil {
		s.err = err
		return
	}

	if err := s.ctx.popStackToX(); err != nil {
		s.err = err
		return
	}

	compOp, ok := compOps[v.Op]
	if !ok {
		s.err = fmt.Errorf("this comparison type is not allowed - this is probably a programmer error: %s", tree.ExpressionString(v))
		return
	}

	jt, jf := s.jt, s.jf
	if v.Op == tree.NEQL {
		jt, jf = jf, jt
	}

	s.ctx.opWithJumps(compOp, 0, jt, jf)
}
631047
func (a *Attribute) numberComparator(b *Attribute) (int, bool) {
	// If they are both integers we do perfect precision comparisons
	if a.Int != nil && b.Int != nil {
		return a.intComparator(b)
	}

	// Push both into the float space
	af := a.getBigFloat()
	bf := b.getBigFloat()
	if af == nil || bf == nil {
		return 0, false
	}

	return af.Cmp(bf), true
}
868423
func LikeCompare(a, b string) (value.BoolValue, bool) {
	// Do we want to always do this replacement?   Or do this at parse time or config?
	if strings.Contains(b, "%") {
		b = strings.Replace(b, "%", "*", -1)
	}
	match, err := glob.Match(b, a)
	if err != nil {
		return value.BoolValueFalse, false
	}
	if match {
		return value.BoolValueTrue, true
	}
	return value.BoolValueFalse, true
}
872572
func (sv *StringVisitor) AcceptComparison(v Comparison) {
	sv.result = fmt.Sprintf("%s(%s ", sv.result, ComparisonSymbols[v.Op])
	v.Left.Accept(sv)
	sv.result += " "
	v.Right.Accept(sv)
	sv.result += ")"
}
1110997
func (w *WebHookPayload) GetCompare() string {
	if w == nil || w.Compare == nil {
		return ""
	}
	return *w.Compare
}
1325895
func RefineComparedConstant(ctx sessionctx.Context, isUnsigned bool, con *Constant, op opcode.Op) (_ *Constant, isAlwaysFalse bool) {
	dt, err := con.Eval(chunk.Row{})
	if err != nil {
		return con, false
	}
	sc := ctx.GetSessionVars().StmtCtx
	intFieldType := types.NewFieldType(mysql.TypeLonglong)
	if isUnsigned {
		intFieldType.Flag |= mysql.UnsignedFlag
	}
	var intDatum types.Datum
	intDatum, err = dt.ConvertTo(sc, intFieldType)
	if err != nil {
		return con, terror.ErrorEqual(err, types.ErrOverflow)
	}
	c, err := intDatum.CompareDatum(sc, &con.Value)
	if err != nil {
		return con, false
	}
	if c == 0 {
		return &Constant{
			Value:        intDatum,
			RetType:      intFieldType,
			DeferredExpr: con.DeferredExpr,
		}, false
	}
	switch op {
	case opcode.LT, opcode.GE:
		resultExpr := NewFunctionInternal(ctx, ast.Ceil, types.NewFieldType(mysql.TypeUnspecified), con)
		if resultCon, ok := resultExpr.(*Constant); ok {
			return tryToConvertConstantInt(ctx, isUnsigned, resultCon)
		}
	case opcode.LE, opcode.GT:
		resultExpr := NewFunctionInternal(ctx, ast.Floor, types.NewFieldType(mysql.TypeUnspecified), con)
		if resultCon, ok := resultExpr.(*Constant); ok {
			return tryToConvertConstantInt(ctx, isUnsigned, resultCon)
		}
	case opcode.NullEQ, opcode.EQ:
		switch con.RetType.EvalType() {
		// An integer value equal or NULL-safe equal to a float value which contains
		// non-zero decimal digits is definitely false.
		// e.g.,
		//   1. "integer  =  1.1" is definitely false.
		//   2. "integer <=> 1.1" is definitely false.
		case types.ETReal, types.ETDecimal:
			return con, true
		case types.ETString:
			// We try to convert the string constant to double.
			// If the double result equals the int result, we can return the int result;
			// otherwise, the compare function will be false.
			var doubleDatum types.Datum
			doubleDatum, err = dt.ConvertTo(sc, types.NewFieldType(mysql.TypeDouble))
			if err != nil {
				return con, false
			}
			if c, err = doubleDatum.CompareDatum(sc, &intDatum); err != nil {
				return con, false
			}
			if c != 0 {
				return con, true
			}
			return &Constant{
				Value:        intDatum,
				RetType:      intFieldType,
				DeferredExpr: con.DeferredExpr,
			}, false
		}
	}
	return con, false
}
890500
func NewCompareFilter(compareOp CompareType, comparatorObj Comparator) *CompareFilter {
	op := pb.CompareType(compareOp)
	obj, err := comparatorObj.ConstructPBComparator()
	if err != nil {
		panic(err)
	}
	return &CompareFilter{
		CompareOp:  &op,
		Comparator: obj,
	}
}
902645
func alphaComp(bg, fg fcolor.RGBAF64) fcolor.RGBAF64 {
	fg.Clamp()
	fga := fg.A

	r := (fg.R * fga / 1) + ((1 - fga) * bg.R / 1)
	g := (fg.G * fga / 1) + ((1 - fga) * bg.G / 1)
	b := (fg.B * fga / 1) + ((1 - fga) * bg.B / 1)
	a := bg.A + fga

	return fcolor.RGBAF64{R: r, G: g, B: b, A: a}
}
380943
func (v *Validator) LessOrEqual(field string, value float64) *ValidationResult {
	return v.inequality(field, value, lessOrEqual, "less than or equal to")
}
719265
func (v Vector) LesserEqual(b Vector) bool {
	comp := v.Compare(b)
	return comp == Lesser || comp == Equal
}
460675
func HighlightPreTagEqual(o1, o2 *HighlightPreTagOption) bool {
	if o1 != nil {
		return o1.Equal(o2)
	}
	if o2 != nil {
		return o2.Equal(o1)
	}
	return true
}
1122444
func AnalyticsEqual(o1, o2 *AnalyticsOption) bool {
	if o1 != nil {
		return o1.Equal(o2)
	}
	if o2 != nil {
		return o2.Equal(o1)
	}
	return true
}
714885
func gorocksdb_comparator_compare(idx int, cKeyA *C.char, cKeyALen C.size_t, cKeyB *C.char, cKeyBLen C.size_t) C.int {
	keyA := charToByte(cKeyA, cKeyALen)
	keyB := charToByte(cKeyB, cKeyBLen)
	return C.int(comperators.Get(idx).(comperatorWrapper).comparator.Compare(keyA, keyB))
}
1346851
func compare(nodeLow, ivLow int64, nodeID, ivID uint64) int {
	if ivLow > nodeLow {
		return 1
	}

	if ivLow < nodeLow {
		return 0
	}

	return intFromBool(ivID > nodeID)
}
437255
func (f Filter) GreaterThanOrEqual(val interface{}) Filter {
	f.Op = ">="
	f.Val = val
	return f
}
558630
func (s *fullArgumentSplitterSimplifier) AcceptComparison(a tree.Comparison) {
	l := s.Transform(a.Left)
	r := s.Transform(a.Right)

	pral, okal := potentialExtractFullArgument(l)
	prnlLow, prnlHi, oknl := potentialExtractValueParts(l)

	prar, okar := potentialExtractFullArgument(r)
	prnrLow, prnrHi, oknr := potentialExtractValueParts(r)

	if okal && oknr {
		switch a.Op {
		case tree.EQL:
			s.Result = tree.And{
				Left:  tree.Comparison{Op: a.Op, Left: tree.Argument{Type: tree.Low, Index: pral}, Right: tree.NumericLiteral{prnrLow}},
				Right: tree.Comparison{Op: a.Op, Left: tree.Argument{Type: tree.Hi, Index: pral}, Right: tree.NumericLiteral{prnrHi}},
			}
		case tree.BITSET:
			s.Result = tree.And{
				Left: tree.Comparison{Op: tree.EQL, Left: tree.Arithmetic{Op: tree.BINAND, Left: tree.Argument{Type: tree.Low, Index: pral}, Right: tree.NumericLiteral{prnrLow}}, Right: tree.NumericLiteral{prnrLow}},

				Right: tree.Comparison{Op: tree.EQL, Left: tree.Arithmetic{Op: tree.BINAND, Left: tree.Argument{Type: tree.Hi, Index: pral}, Right: tree.NumericLiteral{prnrHi}}, Right: tree.NumericLiteral{prnrHi}},
			}
		case tree.NEQL:
			s.Result = tree.Or{
				Left:  tree.Comparison{Op: a.Op, Left: tree.Argument{Type: tree.Low, Index: pral}, Right: tree.NumericLiteral{prnrLow}},
				Right: tree.Comparison{Op: a.Op, Left: tree.Argument{Type: tree.Hi, Index: pral}, Right: tree.NumericLiteral{prnrHi}},
			}
		case tree.GT, tree.GTE:
			s.Result = tree.Or{
				Left: tree.Comparison{Op: tree.GT, Left: tree.Argument{Type: tree.Hi, Index: pral}, Right: tree.NumericLiteral{prnrHi}},
				Right: tree.And{
					Left:  tree.Comparison{Op: tree.EQL, Left: tree.Argument{Type: tree.Hi, Index: pral}, Right: tree.NumericLiteral{prnrHi}},
					Right: tree.Comparison{Op: a.Op, Left: tree.Argument{Type: tree.Low, Index: pral}, Right: tree.NumericLiteral{prnrLow}},
				},
			}
		default:
			panic("shouldn't happen")
		}
	} else if okar && oknl {
		switch a.Op {
		case tree.EQL:
			s.Result = tree.And{
				Left:  tree.Comparison{Op: a.Op, Left: tree.NumericLiteral{prnlLow}, Right: tree.Argument{Type: tree.Low, Index: prar}},
				Right: tree.Comparison{Op: a.Op, Left: tree.NumericLiteral{prnlHi}, Right: tree.Argument{Type: tree.Hi, Index: prar}},
			}
		case tree.BITSET:
			s.Result = tree.And{
				Left:  tree.Comparison{Op: tree.EQL, Left: tree.Arithmetic{Op: tree.BINAND, Left: tree.NumericLiteral{prnlLow}, Right: tree.Argument{Type: tree.Low, Index: prar}}, Right: tree.Argument{Type: tree.Low, Index: prar}},
				Right: tree.Comparison{Op: tree.EQL, Left: tree.Arithmetic{Op: tree.BINAND, Left: tree.NumericLiteral{prnlHi}, Right: tree.Argument{Type: tree.Hi, Index: prar}}, Right: tree.Argument{Type: tree.Hi, Index: prar}},
			}
		case tree.NEQL:
			s.Result = tree.Or{
				Left:  tree.Comparison{Op: a.Op, Left: tree.NumericLiteral{prnlLow}, Right: tree.Argument{Type: tree.Low, Index: prar}},
				Right: tree.Comparison{Op: a.Op, Left: tree.NumericLiteral{prnlHi}, Right: tree.Argument{Type: tree.Hi, Index: prar}},
			}
		case tree.GT, tree.GTE:
			s.Result = tree.Or{
				Left: tree.Comparison{Op: tree.GT, Left: tree.NumericLiteral{prnlHi}, Right: tree.Argument{Type: tree.Hi, Index: prar}},
				Right: tree.And{
					Left:  tree.Comparison{Op: tree.EQL, Left: tree.NumericLiteral{prnlHi}, Right: tree.Argument{Type: tree.Hi, Index: prar}},
					Right: tree.Comparison{Op: a.Op, Left: tree.NumericLiteral{prnlLow}, Right: tree.Argument{Type: tree.Low, Index: prar}},
				},
			}
		default:
			panic("shouldn't happen")
		}
	} else if okal && okar {
		switch a.Op {
		case tree.EQL:
			s.Result = tree.And{
				Left:  tree.Comparison{Op: a.Op, Left: tree.Argument{Type: tree.Low, Index: pral}, Right: tree.Argument{Type: tree.Low, Index: prar}},
				Right: tree.Comparison{Op: a.Op, Left: tree.Argument{Type: tree.Hi, Index: pral}, Right: tree.Argument{Type: tree.Hi, Index: prar}},
			}
		case tree.BITSET:
			s.Result = tree.And{
				Left:  tree.Comparison{Op: tree.EQL, Left: tree.Arithmetic{Op: tree.BINAND, Left: tree.Argument{Type: tree.Low, Index: pral}, Right: tree.Argument{Type: tree.Low, Index: prar}}, Right: tree.Argument{Type: tree.Low, Index: prar}},
				Right: tree.Comparison{Op: tree.EQL, Left: tree.Arithmetic{Op: tree.BINAND, Left: tree.Argument{Type: tree.Hi, Index: pral}, Right: tree.Argument{Type: tree.Hi, Index: prar}}, Right: tree.Argument{Type: tree.Hi, Index: prar}},
			}

		case tree.NEQL:
			s.Result = tree.Or{
				Left:  tree.Comparison{Op: a.Op, Left: tree.Argument{Type: tree.Low, Index: pral}, Right: tree.Argument{Type: tree.Low, Index: prar}},
				Right: tree.Comparison{Op: a.Op, Left: tree.Argument{Type: tree.Hi, Index: pral}, Right: tree.Argument{Type: tree.Hi, Index: prar}},
			}
		case tree.GT, tree.GTE:
			s.Result = tree.Or{
				Left: tree.Comparison{Op: tree.GT, Left: tree.Argument{Type: tree.Hi, Index: pral}, Right: tree.Argument{Type: tree.Hi, Index: prar}},
				Right: tree.And{
					Left:  tree.Comparison{Op: tree.EQL, Left: tree.Argument{Type: tree.Hi, Index: pral}, Right: tree.Argument{Type: tree.Hi, Index: prar}},
					Right: tree.Comparison{Op: a.Op, Left: tree.Argument{Type: tree.Low, Index: pral}, Right: tree.Argument{Type: tree.Low, Index: prar}},
				},
			}
		default:
			panic("shouldn't happen")
		}
	} else if okal && a.Op == tree.BITSET {
		s.Result = tree.And{
			Left:  tree.Comparison{Op: tree.EQL, Left: tree.Argument{Type: tree.Hi, Index: pral}, Right: tree.NumericLiteral{0}},
			Right: tree.Comparison{Op: tree.NEQL, Left: tree.Arithmetic{Op: tree.BINAND, Left: tree.Argument{Type: tree.Low, Index: pral}, Right: a.Right}, Right: tree.NumericLiteral{0}},
		}
	} else {
		s.Result = tree.Comparison{Op: a.Op, Left: l, Right: r}
	}
}