// Check if this prop's columns can match by items totally.
430989
func matchItems(p *property.PhysicalProperty, items []*ByItems) bool {
	if len(items) < len(p.Items) {
		return false
	}
	for i, col := range p.Items {
		sortItem := items[i]
		if sortItem.Desc != col.Desc || !sortItem.Expr.Equal(nil, col.Col) {
			return false
		}
	}
	return true
}
858394
func (s String) Has(item string) bool {
	_, contained := s[item]
	return contained
}
1159880
func areColumnsAPrefixOfIndex(potentialPrefix []*schema.TableColumn, index *schema.Index) bool {
	if len(potentialPrefix) > len(index.Columns) {
		return false
	}
	for i := range potentialPrefix {
		if !potentialPrefix[i].Name.Equal(index.Columns[i]) {
			return false
		}
	}
	return true
}
338137
func (p *Selection) matchProperty(prop *requiredProperty, childPlanInfo ...*physicalPlanInfo) *physicalPlanInfo {
	if p.onTable {
		res := p.GetChildByIndex(0).(PhysicalPlan).matchProperty(prop, childPlanInfo...)
		sel := *p
		sel.SetChildren(res.p)
		res.p = &sel
		res.count = uint64(float64(res.count) * selectionFactor)
		return res
	}
	np := *p
	np.SetChildren(childPlanInfo[0].p)
	count := uint64(float64(childPlanInfo[0].count) * selectionFactor)
	return &physicalPlanInfo{p: &np, cost: childPlanInfo[0].cost, count: count}
}
692250
func IsMatches(str, pattern string) bool {
	match, _ := regexp.MatchString(pattern, str)
	return match
}
1177060
func getPropByOrderByItems(items []*ByItems) (*property.PhysicalProperty, bool) {
	propItems := make([]property.Item, 0, len(items))
	for _, item := range items {
		col, ok := item.Expr.(*expression.Column)
		if !ok {
			return nil, false
		}
		propItems = append(propItems, property.Item{Col: col, Desc: item.Desc})
	}
	return &property.PhysicalProperty{Items: propItems}, true
}
1154398
func (fn typeFunc) Matches(types []reflect.Type) bool {
	if len(fn.Extra) != len(types) {
		return false
	}
	// reorder the items in array types and fn.Extra
	// convert the type into string and sort them, check if they are matched
	varMap := make(map[reflect.Type]bool)
	for i := range fn.Extra {
		varMap[fn.Extra[i]] = true
	}
	for i := range types {
		if _, found := varMap[types[i]]; !found {
			return false
		}
	}
	return true
}
896402
func (f Filter) MatchProperty(prop types.DynamicProperty) bool {
	match, ok := f[prop.Name]
	if !ok {
		return false
	}

	if match == prop.Val {
		return true
	}

	ptype := reflect.TypeOf(prop.Val)

	if strings.HasPrefix(ptype.Name(), "ArrayOf") {
		pval := reflect.ValueOf(prop.Val).Field(0)

		for i := 0; i < pval.Len(); i++ {
			prop.Val = pval.Index(i).Interface()

			if f.MatchProperty(prop) {
				return true
			}
		}

		return false
	}

	if reflect.TypeOf(match) != ptype {
		s, ok := match.(string)
		if !ok {
			return false
		}

		// convert if we can
		switch prop.Val.(type) {
		case bool:
			match, _ = strconv.ParseBool(s)
		case int16:
			x, _ := strconv.ParseInt(s, 10, 16)
			match = int16(x)
		case int32:
			x, _ := strconv.ParseInt(s, 10, 32)
			match = int32(x)
		case int64:
			match, _ = strconv.ParseInt(s, 10, 64)
		case float32:
			x, _ := strconv.ParseFloat(s, 32)
			match = float32(x)
		case float64:
			match, _ = strconv.ParseFloat(s, 64)
		case fmt.Stringer:
			prop.Val = prop.Val.(fmt.Stringer).String()
		default:
			if ptype.Kind() != reflect.String {
				return false
			}
			// An enum type we can convert to a string type
			prop.Val = reflect.ValueOf(prop.Val).String()
		}
	}

	switch pval := prop.Val.(type) {
	case string:
		s := match.(string)
		if s == "*" {
			return true // TODO: path.Match fails if s contains a '/'
		}
		m, _ := path.Match(s, pval)
		return m
	default:
		return reflect.DeepEqual(match, pval)
	}
}
1210935
func (s Int) Has(item int) bool {
	_, contained := s[item]
	return contained
}
683792
func (prop Prop) Check(parameters *TestParameters) *TestResult {
	iterations := math.Ceil(float64(parameters.MinSuccessfulTests) / float64(parameters.Workers))
	sizeStep := float64(parameters.MaxSize-parameters.MinSize) / (iterations * float64(parameters.Workers))

	genParameters := GenParameters{
		MinSize:        parameters.MinSize,
		MaxSize:        parameters.MaxSize,
		MaxShrinkCount: parameters.MaxShrinkCount,
		Rng:            parameters.Rng,
	}
	runner := &runner{
		parameters: parameters,
		worker: func(workerIdx int, shouldStop shouldStop) *TestResult {
			var n int
			var d int

			isExhaused := func() bool {
				return n+d > parameters.MinSuccessfulTests &&
					1.0+float64(parameters.Workers*n)*parameters.MaxDiscardRatio < float64(d)
			}

			for !shouldStop() && n < int(iterations) {
				size := float64(parameters.MinSize) + (sizeStep * float64(workerIdx+(parameters.Workers*(n+d))))
				propResult := prop(genParameters.WithSize(int(size)))

				switch propResult.Status {
				case PropUndecided:
					d++
					if isExhaused() {
						return &TestResult{
							Status:    TestExhausted,
							Succeeded: n,
							Discarded: d,
						}
					}
				case PropTrue:
					n++
				case PropProof:
					n++
					return &TestResult{
						Status:    TestProved,
						Succeeded: n,
						Discarded: d,
						Labels:    propResult.Labels,
						Args:      propResult.Args,
					}
				case PropFalse:
					return &TestResult{
						Status:    TestFailed,
						Succeeded: n,
						Discarded: d,
						Labels:    propResult.Labels,
						Args:      propResult.Args,
					}
				case PropError:
					return &TestResult{
						Status:     TestError,
						Succeeded:  n,
						Discarded:  d,
						Labels:     propResult.Labels,
						Error:      propResult.Error,
						ErrorStack: propResult.ErrorStack,
						Args:       propResult.Args,
					}
				}
			}

			if isExhaused() {
				return &TestResult{
					Status:    TestExhausted,
					Succeeded: n,
					Discarded: d,
				}
			}
			return &TestResult{
				Status:    TestPassed,
				Succeeded: n,
				Discarded: d,
			}
		},
	}

	return runner.runWorkers()
}
928575
func (s Int32) HasAll(items ...int32) bool {
	for _, item := range items {
		if !s.Has(item) {
			return false
		}
	}
	return true
}
1366983
func (p Property) IsPolymorphic() bool {
	return len(p.PrimitiveTypes) > 0 || len(p.PrimitiveItemTypes) > 0 || len(p.PrimitiveItemTypes) > 0 || len(p.ItemTypes) > 0 || len(p.Types) > 0
}
662681
func (set *Set) All(items ...interface{}) bool {
	set.lock.RLock()
	defer set.lock.RUnlock()

	for _, item := range items {
		if _, ok := set.items[item]; !ok {
			return false
		}
	}

	return true
}
325837
func (d *Database) Columns(src interface{}, includePk bool) ([]string, error) {
	data, err := getFields(reflect.TypeOf(src))
	if err != nil {
		return nil, err
	}

	var names []string
	for _, elt := range data.columns {
		if !includePk && elt == data.pk {
			continue
		}
		names = append(names, elt)
	}

	return names, nil
}
1231503
func (p *PhysicalProperty) IsPrefix(prop *PhysicalProperty) bool {
	if len(p.Items) > len(prop.Items) {
		return false
	}
	for i := range p.Items {
		if !p.Items[i].Col.Equal(nil, prop.Items[i].Col) || p.Items[i].Desc != prop.Items[i].Desc {
			return false
		}
	}
	return true
}
576983
func ContainsStrings(coll []string, item string) bool {
	for _, a := range coll {
		if a == item {
			return true
		}
	}
	return false
}
970482
func (p plugins) Contains(item Plugin) (bool, int) {
	for idx, i := range p {
		if i.Name() == item.Name() && i.Version() == item.Version() && i.TypeName() == item.TypeName() {
			return true, idx
		}
	}
	return false, -1
}