MCPcopy Create free account
hub / github.com/cel-expr/cel-go / Cost

Function Cost

checker/cost.go:285–303  ·  view source on GitHub ↗

Cost estimates the cost of the parsed and type checked CEL expression.

(checked *ast.AST, estimator CostEstimator, opts ...CostOption)

Source from the content-addressed store, hash-verified

283
284// Cost estimates the cost of the parsed and type checked CEL expression.
285func Cost(checked *ast.AST, estimator CostEstimator, opts ...CostOption) (CostEstimate, error) {
286 c := &coster{
287 checkedAST: checked,
288 estimator: estimator,
289 overloadEstimators: map[string]FunctionEstimator{},
290 exprPaths: map[int64][]string{},
291 localVars: make(scopes),
292 computedSizes: map[int64]SizeEstimate{},
293 computedEntrySizes: map[int64]entrySizeEstimate{},
294 presenceTestCost: FixedCostEstimate(1),
295 }
296 for _, opt := range opts {
297 err := opt(c)
298 if err != nil {
299 return CostEstimate{}, err
300 }
301 }
302 return c.cost(checked.Expr()), nil
303}
304
305type coster struct {
306 // exprPaths maps from Expr Id to field path.

Callers 3

computeCostFunction · 0.92
EstimateCostMethod · 0.92
TestCostFunction · 0.85

Calls 3

costMethod · 0.95
FixedCostEstimateFunction · 0.85
ExprMethod · 0.65

Tested by 2

computeCostFunction · 0.74
TestCostFunction · 0.68