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

Function estimateSubstringCost

ext/strings.go:876–890  ·  view source on GitHub ↗

Cost estimation functions for string extensions. These functions provide compile-time cost estimates proportional to the size of the input string(s), ensuring that the CEL cost system accurately reflects the computational work performed by string operations. estimateSubstringCost estimates the cost

(estimator cost.Estimator, target *cost.AstNode, args []cost.AstNode)

Source from the content-addressed store, hash-verified

874
875// estimateSubstringCost estimates the cost for an O(n) traversal and allocation.
876func estimateSubstringCost(estimator cost.Estimator, target *cost.AstNode, args []cost.AstNode) *cost.CallEstimate {
877 if target == nil || len(args) < 1 || len(args) > 2 {
878 return nil
879 }
880 targetSize := cost.EstimateSize(estimator, *target)
881 evalCost, _ := cost.EstimateStringScan(targetSize)
882
883 start := cost.NodeAsUintValue(args[0], 0)
884 end := targetSize.Max
885 if len(args) == 2 {
886 end = cost.NodeAsUintValue(args[1], end)
887 }
888 resultSize := cost.FixedSizeEstimate(end - start)
889 return cost.NewCallEstimate(evalCost.Add(cost.CallCostEstimate).Add(resultSize.AsCost()), &resultSize)
890}
891
892// splitSize bounds the size of the parts of a string of size n: at most n + 1 parts of at most n
893// each. Under the aggregate strategy the parts hold at most the string's content plus one unit

Callers

nothing calls this directly

Calls 7

EstimateSizeFunction · 0.92
EstimateStringScanFunction · 0.92
NodeAsUintValueFunction · 0.92
FixedSizeEstimateFunction · 0.92
NewCallEstimateFunction · 0.92
AsCostMethod · 0.80
AddMethod · 0.65

Tested by

no test coverage detected