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

Function estimateStringJoinCost

ext/strings.go:1007–1024  ·  view source on GitHub ↗

estimateStringJoinCost estimates cost for string join operations. Join iterates over all list elements and concatenates them, so cost is proportional to the total size of all elements plus separator overhead.

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

Source from the content-addressed store, hash-verified

1005// Join iterates over all list elements and concatenates them, so cost is
1006// proportional to the total size of all elements plus separator overhead.
1007func estimateStringJoinCost(estimator checker.CostEstimator, target *checker.AstNode, args []checker.AstNode) *checker.CallEstimate {
1008 if target == nil {
1009 return nil
1010 }
1011 targetSize := estimateSize(estimator, *target)
1012 sepSize := fixedSizeEstimate(0)
1013 if len(args) >= 1 {
1014 sepSize = estimateSize(estimator, args[0])
1015 }
1016 // Traversal cost proportional to the number of list elements.
1017 traversalCost := targetSize.Add(fixedSizeEstimate(1)).MultiplyByCostFactor(stringCostFactor)
1018 // Result size: sum of element sizes + (n-1) * separator size.
1019 // Worst case estimate: use list size * max element size + list size * separator size.
1020 maxResultSize := safeAdd(safeMul(targetSize.Max, (safeAdd(1, sepSize.Max))), sepSize.Max)
1021 resultSize := rangedSizeEstimate(0, maxResultSize)
1022 cost := traversalCost.Add(resultSize.MultiplyByCostFactor(1)).Add(callCostEstimate)
1023 return callEstimate(cost, &resultSize)
1024}
1025
1026// Runtime cost tracking functions for string extensions.
1027//

Callers

nothing calls this directly

Calls 8

fixedSizeEstimateFunction · 0.85
safeAddFunction · 0.85
safeMulFunction · 0.85
rangedSizeEstimateFunction · 0.85
callEstimateFunction · 0.85
estimateSizeFunction · 0.70
AddMethod · 0.65
MultiplyByCostFactorMethod · 0.45

Tested by

no test coverage detected