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

Function estimateStringSearchCost

ext/strings.go:952–962  ·  view source on GitHub ↗

estimateStringSearchCost estimates cost for O(n*m) string search operations such as indexOf and lastIndexOf.

(estimator checker.CostEstimator, target *checker.AstNode, args []checker.AstNode)

Source from the content-addressed store, hash-verified

950// estimateStringSearchCost estimates cost for O(n*m) string search operations
951// such as indexOf and lastIndexOf.
952func estimateStringSearchCost(estimator checker.CostEstimator, target *checker.AstNode, args []checker.AstNode) *checker.CallEstimate {
953 if target == nil || len(args) < 1 {
954 return nil
955 }
956 targetSize := estimateSize(estimator, *target)
957 needleSize := estimateSize(estimator, args[0])
958 searchSize := targetSize.Multiply(needleSize)
959 searchCost, _ := estimateStringScan(searchSize)
960 // Search cost is proportional to target size * substring size.
961 return callEstimate(searchCost.Add(callCostEstimate), nil)
962}
963
964// estimateStringReplaceCost estimates cost for string replace operations.
965// The cost accounts for search (O(n*m)) and potential output size growth.

Callers

nothing calls this directly

Calls 5

estimateStringScanFunction · 0.85
callEstimateFunction · 0.85
estimateSizeFunction · 0.70
MultiplyMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected