// Binary predicate functions
// Disjoint returns true if the two geometries have no point in common.
552106
func (g *Geometry) Disjoint(other *Geometry) (bool, error) {
	return g.binaryPred("Disjoint", cGEOSDisjoint, other)
}
881861
func JoinPredicate(arr []string, delimeter string, f func(s string) bool) string {
	arrNew := make([]string, 0, len(arr))
	for _, s := range arr {
		if f(s) {
			arrNew = append(arrNew, s)
		}
	}
	return strings.Join(arrNew, delimeter)
}
1117208
func (t Type) Union() ([]string, bool) {
	if !t.IsUnion() {
		return nil, false
	}
	tips := []string{}
	for _, ut := range strings.Split(t.TypeString(), "|") {
		tips = append(tips, strings.TrimSpace(ut))
	}
	return tips, true
}
1297611
func (splitter *Splitter) Split() ([]*querypb.QuerySplit, error) {
	var boundaries []tuple
	var err error
	boundaries, err = splitter.algorithm.generateBoundaries()
	if err != nil {
		return nil, err
	}
	boundaries = append(boundaries, nil)
	splits := []*querypb.QuerySplit{}
	var start tuple
	for _, end := range boundaries {
		splits = append(splits, splitter.constructQueryPart(start, end))
		start = end
	}
	return splits, nil
}
228197
func ObjectDiff(a, b interface{}) string {
	ab, err := json.Marshal(a)
	if err != nil {
		panic(fmt.Sprintf("a: %v", err))
	}
	bb, err := json.Marshal(b)
	if err != nil {
		panic(fmt.Sprintf("b: %v", err))
	}
	return StringDiff(string(ab), string(bb))
}
928163
func (p LogicalJoin) Init(ctx sessionctx.Context) *LogicalJoin {
	p.baseLogicalPlan = newBaseLogicalPlan(ctx, TypeJoin, &p)
	return &p
}
227035
func polyDiv(p, q int) int {
	np := nbit(p)
	nq := nbit(q)
	for ; np >= nq; np-- {
		if p&(1<<(np-1)) != 0 {
			p ^= q << (np - nq)
		}
	}
	return p
}
384712
func (d *Dataset) Join(name string, other *Dataset, sortOption *SortOption) *Dataset {
	return d.DoJoin(name, other, false, false, sortOption)
}
820648
func (j *Journal) AddDisjunction() error {
	sd_journal_add_disjunction, err := getFunction("sd_journal_add_disjunction")
	if err != nil {
		return err
	}

	j.mu.Lock()
	r := C.my_sd_journal_add_disjunction(sd_journal_add_disjunction, j.cjournal)
	j.mu.Unlock()

	if r < 0 {
		return fmt.Errorf("failed to add a disjunction in the match list: %d", syscall.Errno(-r))
	}

	return nil
}
422397
func (u *Unit) RelationsJoined() ([]*Relation, error) {
	return u.relations(func(ru *RelationUnit) (bool, error) {
		return ru.Joined()
	})
}
658282
func (b *BoolValue) Merge(onto *bool) {
	if b.v != nil {
		*onto = *(b.v)
	}
}
48032
func Merge(coll1, coll2 []string) []string {
	m := map[string]struct{}{}
	for _, v := range append(coll1, coll2...) {
		m[v] = struct{}{}
	}
	r := make([]string, 0, len(m))
	for k := range m {
		r = append(r, k)
	}
	return r
}
1219460
func (h Dense) Merge(g Dense) error {
	if len(h) != len(g) {
		return errors.New("size mismatch")
	}
	for i := 0; i < len(h); i += 3 {
		x0, x1, x2 := h[i], h[i+1], h[i+2]
		y0, y1, y2 := g[i], g[i+1], g[i+2]
		const m = ^byte(3)
		xH0, xH1, xH2 := x0&m, x1&m, x2&m
		xL0, xL1, xL2 := x0&^m, x1&^m, x2&^m
		yH0, yH1, yH2 := y0&m, y1&m, y2&m
		yL0, yL1, yL2 := y0&^m, y1&^m, y2&^m
		var r0, r1, r2 byte
		if xH0 > yH0 {
			r0 = xH0
		} else {
			r0 = yH0
		}
		if xH1 > yH1 {
			r1 = xH1
		} else {
			r1 = yH1
		}
		if xH2 > yH2 {
			r2 = xH2
		} else {
			r2 = yH2
		}
		xx := xL0<<4 ^ xL1<<2 ^ xL2
		yy := yL0<<4 ^ yL1<<2 ^ yL2
		if xx > yy {
			h[i] = r0 ^ xL0
			h[i+1] = r1 ^ xL1
			h[i+2] = r2 ^ xL2
		} else {
			h[i] = r0 ^ yL0
			h[i+1] = r1 ^ yL1
			h[i+2] = r2 ^ yL2
		}
	}
	return nil
}
1342714
func CompareBinary(left, right BinaryJSON) int {
	precedence1 := jsonTypePrecedences[left.Type()]
	precedence2 := jsonTypePrecedences[right.Type()]
	var cmp int
	if precedence1 == precedence2 {
		if precedence1 == jsonTypePrecedences["NULL"] {
			// for JSON null.
			cmp = 0
		}
		switch left.TypeCode {
		case TypeCodeLiteral:
			// false is less than true.
			cmp = int(right.Value[0]) - int(left.Value[0])
		case TypeCodeInt64, TypeCodeUint64, TypeCodeFloat64:
			leftFloat := i64AsFloat64(left.GetInt64(), left.TypeCode)
			rightFloat := i64AsFloat64(right.GetInt64(), right.TypeCode)
			cmp = compareFloat64PrecisionLoss(leftFloat, rightFloat)
		case TypeCodeString:
			cmp = bytes.Compare(left.GetString(), right.GetString())
		case TypeCodeArray:
			leftCount := left.GetElemCount()
			rightCount := right.GetElemCount()
			for i := 0; i < leftCount && i < rightCount; i++ {
				elem1 := left.arrayGetElem(i)
				elem2 := right.arrayGetElem(i)
				cmp = CompareBinary(elem1, elem2)
				if cmp != 0 {
					return cmp
				}
			}
			cmp = leftCount - rightCount
		case TypeCodeObject:
			// only equal is defined on two json objects.
			// larger and smaller are not defined.
			cmp = bytes.Compare(left.Value, right.Value)
		}
	} else {
		cmp = precedence1 - precedence2
	}
	return cmp
}
1205336
func Compare(a, b interface{}) Diff {
	mapA := map[string]interface{}{}
	mapB := map[string]interface{}{}

	jsonA, _ := json.Marshal(a)
	jsonB, _ := json.Marshal(b)

	json.Unmarshal(jsonA, &mapA)
	json.Unmarshal(jsonB, &mapB)

	return compareStringMaps(mapA, mapB)
}
248375
func join(row virtualRow, relations map[string]*Relation, predicates []joiner, predicateIndex int, selectPredicates []PredicateLinker, functors []selectFunctor) error {

	// Skip directly to selectRows if there is no joiner to run
	if len(predicates) == 0 {
		return selectRows(row, selectPredicates, functors)
	}

	// get current predicates
	predicate := predicates[predicateIndex]

	// last := is it last join ?
	last := false
	if predicateIndex >= len(predicates)-1 {
		last = true
	}

	// for each row in relations[pred.Table()]
	r := relations[predicate.On()]
	for i := range r.rows {
		ok, err := predicate.Evaluate(row, r, i)
		if err != nil {
			return err
		}
		// if predicate not ok
		if !ok {
			continue
		}

		// combine columns to existing virtual row
		for index := range r.rows[i].Values {
			v := Value{
				v:      r.rows[i].Values[index],
				valid:  true,
				lexeme: r.table.attributes[index].name,
				table:  r.table.name,
			}
			row[v.table+"."+v.lexeme] = v
		}

		// if last predicate
		if last {
			err = selectRows(row, selectPredicates, functors)
		} else {
			err = join(row, relations, predicates, predicateIndex+1, selectPredicates, functors)
		}
		if err != nil {
			return err
		}
	}

	return nil
}
1053876
func (p *parser) parseJoin() (*Decl, error) {
	joinDecl, err := p.consumeToken(JoinToken)
	if err != nil {
		return nil, err
	}

	// TABLE NAME
	tableDecl, err := p.parseAttribute()
	if err != nil {
		return nil, err
	}
	joinDecl.Add(tableDecl)

	// ON
	onDecl, err := p.consumeToken(OnToken)
	if err != nil {
		return nil, err
	}
	// onDecl := NewDecl(t)
	joinDecl.Add(onDecl)

	// ATTRIBUTE
	leftAttributeDecl, err := p.parseAttribute()
	if err != nil {
		return nil, err
	}
	onDecl.Add(leftAttributeDecl)

	// EQUAL
	equalAttr, err := p.consumeToken(EqualityToken)
	if err != nil {
		return nil, err
	}
	onDecl.Add(equalAttr)

	//ATTRIBUTE
	rightAttributeDecl, err := p.parseAttribute()
	if err != nil {
		return nil, err
	}
	onDecl.Add(rightAttributeDecl)

	return joinDecl, nil
}