当前位置: 首页>>代码示例>>Golang>>正文


Golang expression.And类代码示例

本文整理汇总了Golang中github.com/couchbase/query/expression.And的典型用法代码示例。如果您正苦于以下问题:Golang And类的具体用法?Golang And怎么用?Golang And使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了And类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: newSubsetAnd

func newSubsetAnd(expr *expression.And) *subsetAnd {
	rv := &subsetAnd{}
	rv.test = func(expr2 expression.Expression) (bool, error) {
		for _, child := range expr.Operands() {
			if SubsetOf(child, expr2) {
				return true, nil
			}
		}

		switch expr2 := expr2.(type) {
		case *expression.And:
			for _, child2 := range expr2.Operands() {
				if !SubsetOf(expr, child2) {
					return false, nil
				}
			}

			return true, nil
		}

		return false, nil
	}

	return rv
}
开发者ID:pkdevboxy,项目名称:query,代码行数:25,代码来源:subset_and.go

示例2: newSargAnd

func newSargAnd(pred *expression.And) *sargAnd {
	rv := &sargAnd{}
	rv.sarger = func(expr2 expression.Expression) (spans plan.Spans, err error) {
		if SubsetOf(pred, expr2) {
			return _SELF_SPANS, nil
		}

		var s plan.Spans
		for _, op := range pred.Operands() {
			s, err = sargFor(op, expr2, rv.MissingHigh())
			if err != nil {
				return nil, err
			}

			if len(s) == 0 {
				continue
			}

			if len(spans) == 0 {
				spans = s.Copy()
			} else {
				spans = constrainSpans(spans, s)
			}
		}

		return
	}

	return rv
}
开发者ID:pkdevboxy,项目名称:query,代码行数:30,代码来源:sarg_and.go

示例3: VisitAnd

func (this *JSConverter) VisitAnd(expr *expression.And) (interface{}, error) {
	var buf bytes.Buffer
	buf.WriteString("(")

	for i, op := range expr.Operands() {
		if i > 0 {
			buf.WriteString(" && ")
		}

		buf.WriteString(this.Visit(op))
	}

	buf.WriteString(")")
	return buf.String(), nil
}
开发者ID:pkdevboxy,项目名称:query,代码行数:15,代码来源:jsconverter.go

示例4: newSargableAnd

func newSargableAnd(pred *expression.And) *sargableAnd {
	rv := &sargableAnd{}
	rv.test = func(expr2 expression.Expression) (bool, error) {
		exprs := expression.Expressions{expr2}
		for _, child := range pred.Operands() {
			if SargableFor(child, exprs) > 0 {
				return true, nil
			}
		}

		return false, nil
	}

	return rv
}
开发者ID:pkdevboxy,项目名称:query,代码行数:15,代码来源:sargable_and.go

示例5: VisitAnd

/*
Apply Disjunctive Normal Form.

Convert ANDs of ORs to ORs of ANDs. For example:

(A OR B) AND C => (A AND C) OR (B AND C)

Also apply constant folding. Remove any constant terms.
*/
func (this *DNF) VisitAnd(expr *expression.And) (interface{}, error) {
	err := expr.MapChildren(this)
	if err != nil {
		return nil, err
	}

	// Constant folding
	var terms expression.Expressions
	for _, term := range expr.Operands() {
		val := term.Value()
		if val == nil {
			if terms == nil {
				terms = make(expression.Expressions, 0, len(expr.Operands()))
			}

			terms = append(terms, term)
			continue
		}

		if !val.Truth() {
			return expression.FALSE_EXPR, nil
		}
	}

	if len(terms) == 0 {
		return expression.TRUE_EXPR, nil
	}

	if len(terms) < len(expr.Operands()) {
		expr = expression.NewAnd(terms...)
	}

	// DNF
	if dnfComplexity(expr, 16) >= 16 {
		return expr, nil
	} else {
		return applyDNF(expr, 0), nil
	}
}
开发者ID:pkdevboxy,项目名称:query,代码行数:48,代码来源:dnf.go

示例6: applyDNF

/*
Bounded DNF, to mitigate combinatorial worst-case.

Internally apply Disjunctive Normal Form.

Convert ANDs of ORs to ORs of ANDs. For example:

(A OR B) AND C => (A AND C) OR (B AND C)
*/
func applyDNF(expr *expression.And, level int) expression.Expression {
	na := len(expr.Operands())
	if na > 4 {
		return expr
	}

	for i, aterm := range expr.Operands() {
		switch aterm := aterm.(type) {
		case *expression.Or:
			no := len(aterm.Operands())
			if no*na > 8 {
				return expr
			}

			oterms := make(expression.Expressions, no)

			for j, oterm := range aterm.Operands() {
				aterms := make(expression.Expressions, na)
				for ii, atrm := range expr.Operands() {
					if ii == i {
						aterms[ii] = oterm
					} else {
						aterms[ii] = atrm
					}
				}

				if level > 2 {
					oterms[j] = expression.NewAnd(aterms...)
				} else {
					oterms[j] = applyDNF(expression.NewAnd(aterms...), level+1)
				}
			}

			rv := expression.NewOr(oterms...)
			return rv
		}
	}

	return expr
}
开发者ID:pkdevboxy,项目名称:query,代码行数:49,代码来源:dnf.go


注:本文中的github.com/couchbase/query/expression.And类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。