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

Function estimateListDistinct

ext/lists.go:759–781  ·  view source on GitHub ↗

Compute an O(n^2) with a cost factor of 2, equivalent to sets.contains with a result list which can vary in size from 1 element to the original list size.

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

Source from the content-addressed store, hash-verified

757// Compute an O(n^2) with a cost factor of 2, equivalent to sets.contains with a result list
758// which can vary in size from 1 element to the original list size.
759func estimateListDistinct(estimator checker.CostEstimator, target *checker.AstNode, args []checker.AstNode) *checker.CallEstimate {
760 if target == nil || len(args) != 0 {
761 return nil
762 }
763 sz := estimateSize(estimator, *target)
764 elemType := types.DynType
765 tType := (*target).Type()
766 if tType.Kind() == types.ListKind && len(tType.Parameters()) > 0 {
767 elemType = tType.Parameters()[0]
768 }
769 itemSize := estimateItemSize(estimator, *target)
770 elemCost := estimateElementEqualityCost(estimator, elemType, itemSize)
771
772 costSize := sz.Multiply(sz)
773 cost := costSize.MultiplyByCost(elemCost).MultiplyByCostFactor(2.0)
774
775 minSize := uint64(0)
776 if sz.Min > 0 {
777 minSize = 1
778 }
779 resultSize := checker.SizeEstimate{Min: minSize, Max: sz.Max}
780 return estimateListCallWithDirectCost(cost, resultSize, true)
781}
782
783// estimateListSort computes an O(n^2) sort operation with a cost factor of 2 for the equality
784// operations against the elements in the list against themselves which occur during the sort computation.

Callers

nothing calls this directly

Calls 10

estimateItemSizeFunction · 0.85
ParametersMethod · 0.80
MultiplyByCostMethod · 0.80
estimateSizeFunction · 0.70
TypeMethod · 0.65
KindMethod · 0.65
MultiplyMethod · 0.65
MultiplyByCostFactorMethod · 0.45

Tested by

no test coverage detected