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

Function extractCostTracker

ext/regex.go:412–424  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

410}
411
412func extractCostTracker() interpreter.FunctionTracker {
413 return func(args []ref.Val, result ref.Val) *uint64 {
414 targetCost := float64(safeAdd(actualSize(args[0]), 1)) * common.StringTraversalCostFactor
415 regexCost := float64(safeAdd(actualSize(args[1]), 1)) * common.RegexStringLengthCostFactor
416 // Actual search cost calculation = targetCost + regexCost
417 searchCost := targetCost * regexCost
418 // The total cost is the base call cost + search cost + result string allocation.
419 totalCost := float64(callCost) + searchCost + float64(actualSize(result))
420 // Round up and convert to uint64 for the final cost.
421 finalCost := uint64(math.Ceil(totalCost))
422 return &finalCost
423 }
424}
425
426func extractAllCostTracker() interpreter.FunctionTracker {
427 return func(args []ref.Val, result ref.Val) *uint64 {

Callers 1

ProgramOptionsMethod · 0.85

Calls 2

safeAddFunction · 0.85
actualSizeFunction · 0.70

Tested by

no test coverage detected