MCPcopy Create free account
hub / github.com/expr-lang/expr / Visit

Method Visit

optimizer/count_threshold.go:16–54  ·  view source on GitHub ↗
(node *Node)

Source from the content-addressed store, hash-verified

14type countThreshold struct{}
15
16func (*countThreshold) Visit(node *Node) {
17 binary, ok := (*node).(*BinaryNode)
18 if !ok {
19 return
20 }
21
22 count, ok := binary.Left.(*BuiltinNode)
23 if !ok || count.Name != "count" || len(count.Arguments) != 2 {
24 return
25 }
26
27 integer, ok := binary.Right.(*IntegerNode)
28 if !ok || integer.Value < 0 {
29 return
30 }
31
32 var threshold int
33 switch binary.Operator {
34 case ">":
35 threshold = integer.Value + 1
36 case ">=":
37 threshold = integer.Value
38 case "<":
39 threshold = integer.Value
40 case "<=":
41 threshold = integer.Value + 1
42 default:
43 return
44 }
45
46 // Skip if threshold is 0 or 1 (handled by count_any optimizer)
47 if threshold <= 1 {
48 return
49 }
50
51 // Set threshold on the count node for early termination
52 // The original comparison remains unchanged
53 count.Threshold = &threshold
54}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected