case "replace":
if target != nil && len(args) >= 2 {
sz := l.sizeEstimate(*target)
toReplaceSz := l.sizeEstimate(args[0])
if toReplaceSz.Min == 0 {
toReplaceSz.Min = 1 // replace will replace each char with the replacement if an empty "to replace" string is given
}
replaceWithSz := l.sizeEstimate(args[1])
fmt.Printf("replace sz: %v\n", sz)
fmt.Printf("toReplaceSz: %v\n", toReplaceSz)
fmt.Printf("replaceWithSz: %v\n", replaceWithSz)
// smallest possible result: smallest input size composed of the largest possible substrings being replaced by smallest possible replacement
minSz := uint64(math.Ceil(float64(sz.Min)/float64(toReplaceSz.Max))) * replaceWithSz.Min
// largest possible result: largest input size composed of the smallest possible substrings being replaced by largest possible replacement
maxSz := uint64(math.Ceil(float64(sz.Max)/float64(toReplaceSz.Min))) * replaceWithSz.Max
fmt.Printf("float64(sz.Max): %v, float64(toReplaceSz.Min): %v\n", float64(sz.Max), float64(toReplaceSz.Min))
fmt.Printf("math.Ceil: %v\n", math.Ceil(float64(sz.Max)/float64(toReplaceSz.Min)))
fmt.Printf("uint64: %v\n", uint64(math.Ceil(float64(sz.Max)/float64(toReplaceSz.Min))))
fmt.Printf("*: %v", uint64(math.Ceil(float64(sz.Max)/float64(toReplaceSz.Min)))*replaceWithSz.Max)
// cost is the traversal plus the construction of the result
fmt.Printf(" minSz: %v, maxSz: %v\n", minSz, maxSz)
return &checker.CallEstimate{CostEstimate: sz.MultiplyByCostFactor(2 * common.StringTraversalCostFactor), ResultSize: &checker.SizeEstimate{Min: minSz, Max: maxSz}}
}
ppc64le
replace sz: {0 3145726}
toReplaceSz: {1 8}
replaceWithSz: {0 16}
float64(sz.Max): 3.145726e+06, float64(toReplaceSz.Min): 1
math.Ceil: 3.145726e+06
uint64: 3145726
*: 50331616 minSz: 0, maxSz: 50331616
checking size string_replace_string_string, cost: {4 629150}, resultSize: &{0 50331616}
EstimateCallCost: _==_
=== RUN TestCostEstimation/extended_library_replace/set_maxLength
EstimateCallCost: replace
replace sz: {0 16}
toReplaceSz: {1 8}
replaceWithSz: {0 16}
float64(sz.Max): 16, float64(toReplaceSz.Min): 1
math.Ceil: 16
uint64: 16
*: 256 minSz: 0, maxSz: 256
checking size string_replace_string_string, cost: {4 8}, resultSize: &{0 256}
EstimateCallCost: _==_
--- PASS: TestCostEstimation (0.17s)
--- PASS: TestCostEstimation/extended_library_replace (0.16s)
--- PASS: TestCostEstimation/extended_library_replace/calc_maxLength (0.14s)
--- PASS: TestCostEstimation/extended_library_replace/set_maxLength (0.01s)
PASS
ok k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel 0.734s
amd64:
replace sz: {0 3145726}
toReplaceSz: {1 8}
replaceWithSz: {0 16}
float64(sz.Max): 3.145726e+06, float64(toReplaceSz.Min): 1
math.Ceil: 3.145726e+06
uint64: 3145726
*: 50331616 minSz: 0, maxSz: 50331616
=== RUN TestCostEstimation/extended_library_replace/set_maxLength
replace sz: {0 16}
toReplaceSz: {1 8}
replaceWithSz: {0 16}
float64(sz.Max): 16, float64(toReplaceSz.Min): 1
math.Ceil: 16
uint64: 16
*: 256 minSz: 0, maxSz: 256
--- PASS: TestCostEstimation (0.02s)
--- PASS: TestCostEstimation/extended_library_replace (0.01s)
--- PASS: TestCostEstimation/extended_library_replace/calc_maxLength (0.01s)
--- PASS: TestCostEstimation/extended_library_replace/set_maxLength (0.00s)
PASS