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

Function estimateStringSearchCost

ext/strings.go:951–961  ·  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

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