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

Function estimateSubstringCost

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

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