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

Function estimateExtractAllCost

ext/regex.go:359–380  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

357}
358
359func estimateExtractAllCost() checker.FunctionEstimator {
360 return func(c checker.CostEstimator, target *checker.AstNode, args []checker.AstNode) *checker.CallEstimate {
361 if len(args) == 2 {
362 targetSize := estimateSize(c, args[0])
363 // Fixed size estimate of +1 is added for safety from zero size args.
364 // The target cost is the size of the target string, scaled by a traversal factor.
365 targetCost := targetSize.Add(fixedSizeEstimate(1)).MultiplyByCostFactor(common.StringTraversalCostFactor)
366 // The regex cost is the size of the regex pattern, scaled by a complexity factor.
367 regexCost := estimateSize(c, args[1]).Add(fixedSizeEstimate(1)).MultiplyByCostFactor(common.RegexStringLengthCostFactor)
368 // The result is a list of strings. Worst Case: it's contents are the size of the entire target.
369 resultSize := rangedSizeEstimate(0, targetSize.Max)
370 // The cost to allocate the result list is its base cost plus the size of its contents.
371 allocationSize := resultSize.Add(fixedSizeEstimate(common.ListCreateBaseCost))
372 // The total cost is the search cost (target + regex) plus the allocation cost for the result list.
373 return callEstimate(
374 targetCost.Multiply(regexCost).Add(checker.CostEstimate(allocationSize)),
375 &resultSize,
376 )
377 }
378 return nil
379 }
380}
381
382func estimateReplaceCost() checker.FunctionEstimator {
383 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