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)
| 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. |
| 759 | func 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. |
nothing calls this directly
no test coverage detected