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

Function estimateSubstringCost

ext/strings.go:934–948  ·  view source on GitHub ↗

estimateSubstringCost estimates the cost for an O(n) traversal and allocation.

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

Source from the content-addressed store, hash-verified

932
933// estimateSubstringCost estimates the cost for an O(n) traversal and allocation.
934func estimateSubstringCost(estimator checker.CostEstimator, target *checker.AstNode, args []checker.AstNode) *checker.CallEstimate {
935 if target == nil || len(args) < 1 || len(args) > 2 {
936 return nil
937 }
938 targetSize := estimateSize(estimator, *target)
939 cost, _ := estimateStringScan(targetSize)
940
941 start := nodeAsUintValue(args[0], 0)
942 end := targetSize.Max
943 if len(args) == 2 {
944 end = nodeAsUintValue(args[1], end)
945 }
946 resultSize := fixedSizeEstimate(end - start)
947 return callEstimate(cost.Add(callCostEstimate).Add(resultSize.AsCost()), &resultSize)
948}
949
950// estimateStringSearchCost estimates cost for O(n*m) string search operations
951// such as indexOf and lastIndexOf.

Callers

nothing calls this directly

Calls 7

estimateStringScanFunction · 0.85
nodeAsUintValueFunction · 0.85
fixedSizeEstimateFunction · 0.85
callEstimateFunction · 0.85
AsCostMethod · 0.80
estimateSizeFunction · 0.70
AddMethod · 0.65

Tested by

no test coverage detected