eaiovnaovbqoebvqoeavibavo 3 bW#@sdZGdddeZdS)zA simple Set class.c@seZdZdZdgZdDddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;Z dd?Z"d@dAZ#dBdCZ$dS)ESeta'A simple set class. Sets are not in Python until 2.3, and rdata are not immutable so we cannot use sets.Set anyway. This class implements subset of the 2.3 Set interface using a list as the container. @ivar items: A list of the items which are in the set @type items: listitemsNcCs*g|_|dk r&x|D]}|j|qWdS)zvInitialize the set. @param items: the initial set of items @type items: any iterable or None N)radd)selfritemr/usr/lib/python3.6/set.py__init__ s z Set.__init__cCsdt|jS)Nzdns.simpleset.Set(%s))reprr)rrrr__repr__,sz Set.__repr__cCs||jkr|jj|dS)zAdd an item to the set.N)rappend)rrrrrr/s zSet.addcCs|jj|dS)zRemove an item from the set.N)rremove)rrrrrr 4sz Set.removec Cs*y|jj|Wntk r$YnXdS)z'Remove an item from the set if present.N)rr ValueError)rrrrrdiscard8sz Set.discardcCs |j}|j|}t|j|_|S)aMake a (shallow) copy of the set. There is a 'clone protocol' that subclasses of this class should use. To make a copy, first call your super's _clone() method, and use the object returned as the new instance. Then make shallow copies of the attributes defined in the subclass. This protocol allows us to write the set algorithms that return new instances (e.g. union) once, and keep using them in subclasses. ) __class____new__listr)rclsobjrrr_clone?s   z Set._clonecCs|jS)z!Make a (shallow) copy of the set.)r)rrrr__copy__Qsz Set.__copy__cCs|jS)z!Make a (shallow) copy of the set.)r)rrrrcopyUszSet.copycCs<t|tstd||krdSx|jD]}|j|q&WdS)zUpdate the set, adding any elements from other which are not already in the set. @param other: the collection of items with which to update the set @type other: Set object zother must be a Set instanceN) isinstancerr rr)rotherrrrr union_updateYs   zSet.union_updatecCsLt|tstd||krdSx(t|jD]}||jkr*|jj|q*WdS)zUpdate the set, removing any elements from other which are not in both sets. @param other: the collection of items with which to update the set @type other: Set object zother must be a Set instanceN)rrr rrr )rrrrrrintersection_updatefs  zSet.intersection_updatecCs@t|tstd||kr"g|_nx|jD]}|j|q*WdS)zUpdate the set, removing any elements from other which are in the set. @param other: the collection of items with which to update the set @type other: Set object zother must be a Set instanceN)rrr rr)rrrrrrdifference_updatevs   zSet.difference_updatecCs|j}|j||S)zReturn a new set which is the union of I{self} and I{other}. @param other: the other set @type other: Set object @rtype: the same type as I{self} )rr)rrrrrrunions z Set.unioncCs|j}|j||S)zReturn a new set which is the intersection of I{self} and I{other}. @param other: the other set @type other: Set object @rtype: the same type as I{self} )rr)rrrrrr intersections zSet.intersectioncCs|j}|j||S)zReturn a new set which I{self} - I{other}, i.e. the items in I{self} which are not also in I{other}. @param other: the other set @type other: Set object @rtype: the same type as I{self} )rr)rrrrrr differences  zSet.differencecCs |j|S)N)r)rrrrr__or__sz Set.__or__cCs |j|S)N)r)rrrrr__and__sz Set.__and__cCs |j|S)N)r)rrrrr__add__sz Set.__add__cCs |j|S)N)r)rrrrr__sub__sz Set.__sub__cCs|j||S)N)r)rrrrr__ior__s z Set.__ior__cCs|j||S)N)r)rrrrr__iand__s z Set.__iand__cCs|j||S)N)r)rrrrr__iadd__s z Set.__iadd__cCs|j||S)N)r)rrrrr__isub__s z Set.__isub__cCsx|D]}|j|qWdS)zUpdate the set, adding any elements from other which are not already in the set. @param other: the collection of items with which to update the set @type other: any iterable typeN)r)rrrrrrupdates z Set.updatecCs g|_dS)zMake the set empty.N)r)rrrrclearsz Set.clearcCs@x|jD]}||jkrdSqWx|jD]}||jkr&dSq&WdS)NFT)r)rrrrrr__eq__s    z Set.__eq__cCs |j| S)N)r))rrrrr__ne__sz Set.__ne__cCs t|jS)N)lenr)rrrr__len__sz Set.__len__cCs t|jS)N)iterr)rrrr__iter__sz Set.__iter__cCs |j|S)N)r)rirrr __getitem__szSet.__getitem__cCs |j|=dS)N)r)rr/rrr __delitem__szSet.__delitem__cCs4t|tstdx|jD]}||jkrdSqWdS)z?Is I{self} a subset of I{other}? @rtype: bool zother must be a Set instanceFT)rrr r)rrrrrrissubsets    z Set.issubsetcCs4t|tstdx|jD]}||jkrdSqWdS)zAIs I{self} a superset of I{other}? @rtype: bool zother must be a Set instanceFT)rrr r)rrrrrr issupersets    zSet.issuperset)N)%__name__ __module__ __qualname____doc__ __slots__rr rr rrrrrrrrrrrr r!r"r#r$r%r&r'r(r)r*r,r.r0r1r2r3rrrrrsD        rN)r7objectrrrrrs