[Python-ideas] Implement __add__ for set and frozenset

Arnaud Delobelle arnodel at googlemail.com
Thu Jun 5 19:16:47 CEST 2008


On 4 Jun 2008, at 09:45, Raymond Hettinger wrote:
> In the case of intersection and intersection_update, if the inputs  
> are sets or dicts, then they should be processed smallest to  
> largest.  If the inputs are not sets or dicts, then process them in  
> input order.
>
> The other six cases should also be processed in-order (left-to-right).
>


Given that

    A - X - Y - Z

is the same as

   (A-X) & (A-Y) & (A-Z)

If it is a significant optimization to intersect sets from smallest to  
largest (as opposed to just starting with the smallest one and then  
intersecting from left to right), then should the same idea be applied  
to difference, except that obviously you start with the leftmost one  
and sort the others from largest to smallest?

(I am *not* proposing to compute A-X, A-Y, ... and then intersect them!)

-- 
Arnaud




More information about the Python-ideas mailing list