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

Function estimateStringSplitCost

ext/strings.go:989–1002  ·  view source on GitHub ↗

estimateStringSplitCost estimates cost for string split operations. Split creates a list of substrings, so cost includes both traversal and list allocation proportional to the input size.

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

Source from the content-addressed store, hash-verified

987// Split creates a list of substrings, so cost includes both traversal and
988// list allocation proportional to the input size.
989func estimateStringSplitCost(estimator checker.CostEstimator, target *checker.AstNode, args []checker.AstNode) *checker.CallEstimate {
990 if target == nil || len(args) < 1 {
991 return nil
992 }
993 targetSize := estimateSize(estimator, *target)
994 // Traversal cost proportional to input size.
995 traversalCost := targetSize.Add(fixedSizeEstimate(1)).MultiplyByCostFactor(stringCostFactor)
996 // Worst case: split("") produces N elements for a string of size N.
997 resultSize := rangedSizeEstimate(0, targetSize.Max)
998 // Include list creation base cost plus allocation for each element.
999 allocationCost := resultSize.MultiplyByCostFactor(1).Add(checker.FixedCostEstimate(common.ListCreateBaseCost))
1000 cost := traversalCost.Add(allocationCost).Add(callCostEstimate)
1001 return callEstimate(cost, &resultSize)
1002}
1003
1004// estimateStringJoinCost estimates cost for string join operations.
1005// Join iterates over all list elements and concatenates them, so cost is

Callers

nothing calls this directly

Calls 7

FixedCostEstimateFunction · 0.92
fixedSizeEstimateFunction · 0.85
rangedSizeEstimateFunction · 0.85
callEstimateFunction · 0.85
estimateSizeFunction · 0.70
AddMethod · 0.65
MultiplyByCostFactorMethod · 0.45

Tested by

no test coverage detected