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

Function estimateExtractCost

ext/regex.go:338–357  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

336}
337
338func estimateExtractCost() checker.FunctionEstimator {
339 return func(c checker.CostEstimator, target *checker.AstNode, args []checker.AstNode) *checker.CallEstimate {
340 if len(args) == 2 {
341 targetSize := estimateSize(c, args[0])
342 // Fixed size estimate of +1 is added for safety from zero size args.
343 // The target cost is the size of the target string, scaled by a traversal factor.
344 targetCost := targetSize.Add(fixedSizeEstimate(1)).MultiplyByCostFactor(common.StringTraversalCostFactor)
345 // The regex cost is the size of the regex pattern, scaled by a complexity factor.
346 regexCost := estimateSize(c, args[1]).Add(fixedSizeEstimate(1)).MultiplyByCostFactor(common.RegexStringLengthCostFactor)
347 // The result is a single string. Worst Case: it's the size of the entire target.
348 resultSize := rangedSizeEstimate(0, targetSize.Max)
349 // The total cost is the search cost (target + regex) plus the allocation cost for the result string.
350 return callEstimate(
351 regexCost.Multiply(targetCost).Add(checker.CostEstimate(resultSize)),
352 &resultSize,
353 )
354 }
355 return nil
356 }
357}
358
359func estimateExtractAllCost() checker.FunctionEstimator {
360 return func(c checker.CostEstimator, target *checker.AstNode, args []checker.AstNode) *checker.CallEstimate {

Callers 1

CompileOptionsMethod · 0.85

Calls 8

CostEstimateStruct · 0.92
fixedSizeEstimateFunction · 0.85
rangedSizeEstimateFunction · 0.85
callEstimateFunction · 0.85
estimateSizeFunction · 0.70
AddMethod · 0.65
MultiplyMethod · 0.65
MultiplyByCostFactorMethod · 0.45

Tested by

no test coverage detected