// CompareToDef compare this synthdef to another.
13957
func (def *Synthdef) CompareToDef(other *Synthdef) (bool, error) {
	var (
		buf1 = &bytes.Buffer{}
		buf2 = &bytes.Buffer{}
	)
	if err := def.Write(buf1); err != nil {
		return false, err
	}
	if err := other.Write(buf2); err != nil {
		return false, err
	}
	return compareBytes(buf1.Bytes(), buf2.Bytes()), nil
}
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
}
176958
func deriveCompare_1(this, that *string) int {
	if this == nil {
		if that == nil {
			return 0
		}
		return -1
	}
	if that == nil {
		return 1
	}
	return deriveCompare_s(*this, *that)
}
227289
func (a *Attribute) stringComparator(b *Attribute) (int, bool) {
	return strings.Compare(*a.String, *b.String), true
}
78246
func (p *PushEvent) GetCompare() string {
	if p == nil || p.Compare == nil {
		return ""
	}
	return *p.Compare
}
245775
func CompareConfigs(old, new *ucfg.Config, opts ...ucfg.Option) Diff {
	oldKeys := old.FlattenedKeys(opts...)
	newKeys := new.FlattenedKeys(opts...)

	difference := make(map[string]Type)

	// Map for candidates check
	for _, k := range oldKeys {
		difference[k] = Remove
	}

	for _, nk := range newKeys {
		if _, ok := difference[nk]; ok {
			difference[nk] = Keep
		} else {
			difference[nk] = Add
		}
	}

	invert := make(Diff)

	for k, v := range difference {
		invert[v] = append(invert[v], k)
	}

	return invert
}
600808
func (v Version) Compare(o Version) int {
	if v.Major != o.Major {
		if v.Major > o.Major {
			return 1
		}
		return -1
	}
	if v.Minor != o.Minor {
		if v.Minor > o.Minor {
			return 1
		}
		return -1
	}
	if v.Patch != o.Patch {
		if v.Patch > o.Patch {
			return 1
		}
		return -1
	}

	// Quick comparison if a version has no prerelease versions
	if len(v.Pre) == 0 && len(o.Pre) == 0 {
		return 0
	} else if len(v.Pre) == 0 && len(o.Pre) > 0 {
		return 1
	} else if len(v.Pre) > 0 && len(o.Pre) == 0 {
		return -1
	}

	i := 0
	for ; i < len(v.Pre) && i < len(o.Pre); i++ {
		if comp := v.Pre[i].Compare(o.Pre[i]); comp == 0 {
			continue
		} else if comp == 1 {
			return 1
		} else {
			return -1
		}
	}

	// If all pr versions are the equal but one has further prversion, this one greater
	if i == len(v.Pre) && i == len(o.Pre) {
		return 0
	} else if i == len(v.Pre) && i < len(o.Pre) {
		return -1
	} else {
		return 1
	}

}
346451
func (t *T) deepEqual(
	desc string, have, want reflect.Value, ignores []string,
	visited map[uintptr]*visitedNode,
) (diffs []string) {
	for _, ignore := range ignores {
		if desc == ignore {
			return nil
		}
	}
	if !want.IsValid() && !have.IsValid() {
		return nil
	} else if !want.IsValid() && have.IsValid() {
		// This is rare, not sure how to document this better.
		return []string{
			fmt.Sprintf("%s: have invalid or nil object.", desc),
		}
	} else if want.IsValid() && !have.IsValid() {
		// This is rare, not sure how to document this better.
		return []string{
			fmt.Sprintf("%s: wanted a valid, non nil object.", desc),
		}
	} else if want.Type() != have.Type() {
		return []string{fmt.Sprintf(
			"%s: Not the same type have: '%s', want: '%s'",
			desc, have.Type(), want.Type())}
	}

	if want.CanAddr() && have.CanAddr() {
		addr1 := want.UnsafeAddr()
		addr2 := have.UnsafeAddr()
		if addr1 > addr2 {
			// Canonicalize order to reduce number of entries in visited.
			addr1, addr2 = addr2, addr1
		}

		// Short circuit if references are identical ...
		if addr1 == addr2 {
			return []string{}
		}

		// ... or already seen
		h := 17*addr1 + addr2
		seen := visited[h]
		typ := want.Type()
		for p := seen; p != nil; p = p.next {
			if p.a1 == addr1 && p.a2 == addr2 && p.typ == typ {
				return []string{}
			}
		}

		// Remember for later.
		visited[h] = &visitedNode{addr1, addr2, typ, seen}
	}

	// Checks to see if one value is nil, while the other is not.
	checkNil := func() bool {
		if want.IsNil() && !have.IsNil() {
			diffs = append(diffs, fmt.Sprintf("%s: not equal.", desc))
			diffs = append(diffs, fmt.Sprintf("  have: %s", stringValue(have)))
			diffs = append(diffs, "  want: nil")
			return true
		} else if !want.IsNil() && have.IsNil() {
			diffs = append(diffs, fmt.Sprintf("%s: not equal.", desc))
			diffs = append(diffs, "  have: nil")
			diffs = append(diffs, fmt.Sprintf("  want: %s", stringValue(want)))
			return true
		}
		return false
	}

	// Checks to see that the lengths of both objects are equal.
	checkLen := func() bool {
		if want.Len() != have.Len() {
			diffs = append(diffs, fmt.Sprintf(
				"%s: (len(have): %d, len(want): %d)",
				desc, have.Len(), want.Len()))
			diffs = append(diffs, fmt.Sprintf("  have: %s", stringValue(have)))
			diffs = append(diffs, fmt.Sprintf("  want: %s", stringValue(want)))
			return true
		}
		return false
	}

	switch want.Kind() {
	case reflect.Array:
		if !checkLen() {
			for i := 0; i < want.Len(); i++ {
				newdiffs := t.deepEqual(
					fmt.Sprintf("%s[%d]", desc, i),
					have.Index(i), want.Index(i), ignores, visited)
				diffs = append(diffs, newdiffs...)
			}
		}

	case reflect.Chan:
		// Channels are complex to compare so we rely on the existing type
		// checks to assert correctness, and then we add an additional
		// capacity check to assert buffer size.
		hcap := have.Cap()
		wcap := want.Cap()
		if hcap != wcap {
			diffs = append(diffs, fmt.Sprintf(
				"%sCapacities differ:\n  have: %d\n  want: %d",
				desc, hcap, wcap))
			return diffs
		}

	case reflect.Func:
		// Can't do better than this:
		checkNil()

	case reflect.Interface:
		if !checkNil() {
			newdiffs := t.deepEqual(
				desc, have.Elem(), want.Elem(), ignores, visited)
			diffs = append(diffs, newdiffs...)
		}

	case reflect.Map:
		if !checkNil() {
			// Check that the keys are present in both maps.
			for _, k := range want.MapKeys() {
				if !have.MapIndex(k).IsValid() {
					// Add the error.
					diffs = append(diffs, fmt.Sprintf(
						"%sExpected key [%q] is missing.", desc, k))
					diffs = append(diffs, "  have: not present")
					diffs = append(diffs, fmt.Sprintf("  want: %#v",
						want.MapIndex(k)))
					continue
				}
				newdiffs := t.deepEqual(
					fmt.Sprintf("%s[%q] ", desc, k),
					have.MapIndex(k), want.MapIndex(k), ignores, visited)
				diffs = append(diffs, newdiffs...)
			}
			for _, k := range have.MapKeys() {
				if !want.MapIndex(k).IsValid() {
					// Add the error.
					diffs = append(diffs, fmt.Sprintf(
						"%sUnexpected key [%q].", desc, k))
					diffs = append(diffs,
						fmt.Sprintf("  have: %#v", have.MapIndex(k)))
					diffs = append(diffs, "  want: not present")
				}
			}
		}

	case reflect.Ptr:
		newdiffs := t.deepEqual(
			desc, have.Elem(), want.Elem(), ignores, visited)
		diffs = append(diffs, newdiffs...)

	case reflect.Slice:
		if !checkNil() && !checkLen() {
			for i := 0; i < want.Len(); i++ {
				newdiffs := t.deepEqual(
					fmt.Sprintf("%s[%d]", desc, i),
					have.Index(i), want.Index(i), ignores, visited)
				diffs = append(diffs, newdiffs...)
			}
		}

	case reflect.String:
		// We know the underlying type is a string so calling String()
		// will return the underlying value. Trying to call Interface()
		// and assert to a string will panic.
		hstr := have.String()
		wstr := want.String()
		if hstr == wstr {
			// Cheap equality test passed, no need to continue.
			break
		}
		hrunes := []rune(hstr)
		wrunes := []rune(wstr)
		if len(hrunes) != len(wrunes) {
			return []string{
				fmt.Sprintf("%s: len(have) %d != len(want) %d.",
					desc, len(hrunes), len(wrunes)),
				fmt.Sprintf("  have: %#v", hstr),
				fmt.Sprintf("  want: %#v", wstr),
			}
		}
		for i, r := range hrunes {
			if r != wrunes[i] {
				return []string{
					fmt.Sprintf("%s: difference at rune %d.", desc, i),
					fmt.Sprintf("  have: %#v", hstr),
					fmt.Sprintf("  want: %#v", wstr),
				}
			}
		}

	case reflect.Struct:
		for i, n := 0, want.NumField(); i < n; i++ {
			name := want.Type().Field(i).Name
			// Make sure that we don't print a strange error if the
			// first object given to us is a struct.
			if desc == "" {
				newdiffs := t.deepEqual(
					name, have.Field(i), want.Field(i), ignores, visited)
				diffs = append(diffs, newdiffs...)
			} else {
				newdiffs := t.deepEqual(
					fmt.Sprintf("%s.%s", desc, name),
					have.Field(i), want.Field(i), ignores, visited)
				diffs = append(diffs, newdiffs...)
			}
		}

	case reflect.Uintptr:
		// Uintptr's work like UnsafePointers. We can't evaluate them or
		// do much with them so we have to cast them into a number and
		// compare them that way.
		havePtr := have.Uint()
		wantPtr := want.Uint()
		if havePtr != wantPtr {
			return []string{
				fmt.Sprintf("%s: not equal.", desc),
				fmt.Sprintf("  have: %#v", havePtr),
				fmt.Sprintf("  want: %#v", wantPtr),
			}
		}

	case reflect.UnsafePointer:
		// Unsafe pointers can cause us problems as they fall ill of the
		// Interface() restrictions. As such we have to special case them
		// and cast them as integers.
		havePtr := have.Pointer()
		wantPtr := want.Pointer()
		if havePtr != wantPtr {
			return []string{
				fmt.Sprintf("%s: not equal.", desc),
				fmt.Sprintf("  have: %#v", havePtr),
				fmt.Sprintf("  want: %#v", wantPtr),
			}
		}

	case reflect.Bool:
		haveBool := have.Bool()
		wantBool := want.Bool()
		if haveBool != wantBool {
			return []string{
				fmt.Sprintf("%s: not equal.", desc),
				fmt.Sprintf("  have: bool(%t)", haveBool),
				fmt.Sprintf("  want: bool(%t)", wantBool),
			}
		}

	case reflect.Int:
		fallthrough
	case reflect.Int8:
		fallthrough
	case reflect.Int16:
		fallthrough
	case reflect.Int32:
		fallthrough
	case reflect.Int64:
		// Basic integer types.
		haveInt := have.Int()
		wantInt := want.Int()
		if haveInt != wantInt {
			return []string{
				fmt.Sprintf("%s: not equal", desc),
				fmt.Sprintf("  have: %s(%d)", have.Type(), haveInt),
				fmt.Sprintf("  want: %s(%d)", want.Type(), wantInt),
			}
		}

	case reflect.Uint:
		fallthrough
	case reflect.Uint8:
		fallthrough
	case reflect.Uint16:
		fallthrough
	case reflect.Uint32:
		fallthrough
	case reflect.Uint64:
		// Basic unsigned integer types.
		haveUint := have.Uint()
		wantUint := want.Uint()
		if haveUint != wantUint {
			return []string{
				fmt.Sprintf("%s: not equal", desc),
				fmt.Sprintf("  have: %s(%d)", have.Type(), haveUint),
				fmt.Sprintf("  want: %s(%d)", want.Type(), wantUint),
			}
		}

	case reflect.Float32:
		fallthrough
	case reflect.Float64:
		// Float types.
		haveFloat := have.Float()
		wantFloat := want.Float()
		if haveFloat != wantFloat {
			return []string{
				fmt.Sprintf("%s: not equal", desc),
				fmt.Sprintf("  have: %s(%f)", have.Type(), haveFloat),
				fmt.Sprintf("  want: %s(%f)", want.Type(), wantFloat),
			}
		}
	}

	return diffs
}
439890
func (rf *RulerRule) compare(comp int, value interface{}) *RulerRule {
	var comparator string
	switch comp {
	case eq:
		comparator = "eq"
	case neq:
		comparator = "neq"
	case lt:
		comparator = "lt"
	case lte:
		comparator = "lte"
	case gt:
		comparator = "gt"
	case gte:
		comparator = "gte"
	case contains:
		comparator = "contains"
	case matches:
		comparator = "matches"
	case ncontains:
		comparator = "ncontains"
	}

	// if this thing has a comparator already, we need to make a new ruler filter
	if rf.Comparator != "" {
		rf = &RulerRule{
			rf.Ruler,
			&Rule{
				comparator,
				rf.Path,
				value,
			},
		}
		// attach the new filter to the ruler
		rf.Ruler.rules = append(rf.Ruler.rules, rf.Rule)
	} else {
		//if there is no comparator, we can just set things on the current filter
		rf.Comparator = comparator
		rf.Value = value
	}

	return rf
}
1248193
func RankingEqual(o1, o2 *RankingOption) bool {
	if o1 != nil {
		return o1.Equal(o2)
	}
	if o2 != nil {
		return o2.Equal(o1)
	}
	return true
}
133194
func (vn *VecN) ApproxEqualFunc(vn2 *VecN, comp func(float32, float32) bool) bool {
	if vn == nil || vn2 == nil || len(vn.vec) != len(vn2.vec) {
		return false
	}

	for i, el := range vn.vec {
		if !comp(el, vn2.vec[i]) {
			return false
		}
	}

	return true
}
1001490
func (d Duration) CompareString(sc *stmtctx.StatementContext, str string) (int, error) {
	// use MaxFsp to parse the string
	o, err := ParseDuration(sc, str, MaxFsp)
	if err != nil {
		return 0, err
	}

	return d.Compare(o), nil
}
467726
func NewTypeDef(init ...*TypeDef) *TypeDef {
	var o *TypeDef
	if len(init) == 1 {
		o = init[0]
	} else {
		o = new(TypeDef)
	}
	return o
}
1163009
func (args Arguments) Diff(objects []interface{}) (string, int) {
	//TODO: could return string as error and nil for No difference

	var output = "\n"
	var differences int

	var maxArgCount = len(args)
	if len(objects) > maxArgCount {
		maxArgCount = len(objects)
	}

	for i := 0; i < maxArgCount; i++ {
		var actual, expected interface{}
		var actualFmt, expectedFmt string

		if len(objects) <= i {
			actual = "(Missing)"
			actualFmt = "(Missing)"
		} else {
			actual = objects[i]
			actualFmt = fmt.Sprintf("(%[1]T=%[1]v)", actual)
		}

		if len(args) <= i {
			expected = "(Missing)"
			expectedFmt = "(Missing)"
		} else {
			expected = args[i]
			expectedFmt = fmt.Sprintf("(%[1]T=%[1]v)", expected)
		}

		if matcher, ok := expected.(argumentMatcher); ok {
			if matcher.Matches(actual) {
				output = fmt.Sprintf("%s\t%d: PASS:  %s matched by %s\n", output, i, actualFmt, matcher)
			} else {
				differences++
				output = fmt.Sprintf("%s\t%d: FAIL:  %s not matched by %s\n", output, i, actualFmt, matcher)
			}
		} else if reflect.TypeOf(expected) == reflect.TypeOf((*AnythingOfTypeArgument)(nil)).Elem() {

			// type checking
			if reflect.TypeOf(actual).Name() != string(expected.(AnythingOfTypeArgument)) && reflect.TypeOf(actual).String() != string(expected.(AnythingOfTypeArgument)) {
				// not match
				differences++
				output = fmt.Sprintf("%s\t%d: FAIL:  type %s != type %s - %s\n", output, i, expected, reflect.TypeOf(actual).Name(), actualFmt)
			}

		} else {

			// normal checking

			if assert.ObjectsAreEqual(expected, Anything) || assert.ObjectsAreEqual(actual, Anything) || assert.ObjectsAreEqual(actual, expected) {
				// match
				output = fmt.Sprintf("%s\t%d: PASS:  %s == %s\n", output, i, actualFmt, expectedFmt)
			} else {
				// not match
				differences++
				output = fmt.Sprintf("%s\t%d: FAIL:  %s != %s\n", output, i, actualFmt, expectedFmt)
			}
		}

	}

	if differences == 0 {
		return "No differences.", differences
	}

	return output, differences

}
1037565
func (lls *logLevelSetting) Compare(other gorivets.Comparable) int {
	return compare(lls, other.(*logLevelSetting))
}
1211210
func (m MDBXLog) Compare(xlog1, xlog2 xlog.Position) (int, error) {
	if xlog1 == xlog2 {
		return 0, nil
	}
	pos1, err := parseXlog(xlog1)
	if err != nil {
		return 0, err
	}
	pos2, err := parseXlog(xlog2)
	if err != nil {
		return 0, err
	}
	if pos1 > pos2 {
		return 1, nil
	}
	return -1, nil
}
1215669
func compareConstant(ctx sessionctx.Context, fn string, c1, c2 Expression) (int64, bool, error) {
	cmp, err := NewFunction(ctx, fn, types.NewFieldType(mysql.TypeTiny), c1, c2)
	if err != nil {
		return 0, false, err
	}
	return cmp.EvalInt(ctx, chunk.Row{})
}