3 ¢báW#ã@sdZGdd„deƒZdS)zA simple Set class.c@seZdZdZdgZdDdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zd2d3„Zd4d5„Zd6d7„Zd8d9„Zd:d;„Z dd?„Z"d@dA„Z#dBdC„Z$dS)EÚSeta'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: listÚitemsNcCs*g|_|dk r&x|D]}|j|ƒqWdS)zvInitialize the set. @param items: the initial set of items @type items: any iterable or None N)rÚadd)ÚselfrÚitem©rú/usr/lib/python3.6/set.pyÚ__init__ s z Set.__init__cCsdt|jƒS)Nzdns.simpleset.Set(%s))Úreprr)rrrrÚ__repr__,sz Set.__repr__cCs||jkr|jj|ƒdS)zAdd an item to the set.N)rÚappend)rrrrrr/s zSet.addcCs|jj|ƒdS)zRemove an item from the set.N)rÚremove)rrrrrr 4sz Set.removec Cs*y|jj|ƒWntk r$YnXdS)z'Remove an item from the set if present.N)rr Ú ValueError)rrrrrÚdiscard8sz Set.discardcCs |j}|j|ƒ}t|jƒ|_|S)aÞMake 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)rÚclsÚobjrrrÚ_clone?s   z Set._clonecCs|jƒS)z!Make a (shallow) copy of the set.)r)rrrrÚ__copy__Qsz Set.__copy__cCs|jƒS)z!Make a (shallow) copy of the set.)r)rrrrÚcopyUszSet.copycCs<t|tƒstdƒ‚||krdSx|jD]}|j|ƒq&WdS)zÌUpdate 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)rÚotherrrrrÚ union_updateYs   zSet.union_updatecCsLt|tƒstdƒ‚||krdSx(t|jƒD]}||jkr*|jj|ƒq*WdS)zÈUpdate 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 )rrrrrrÚintersection_updatefs  zSet.intersection_updatecCs@t|tƒstdƒ‚||kr"g|_nx|jD]}|j|ƒq*WdS)zÂUpdate 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)rrrrrrÚdifference_updatevs   zSet.difference_updatecCs|jƒ}|j|ƒ|S)z³Return 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)rrrrrrÚunion„s z Set.unioncCs|jƒ}|j|ƒ|S)zºReturn 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)zãReturn 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Ú differenceœs  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)zÊUpdate 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)rrrrrrÚupdateÅs z Set.updatecCs g|_dS)zMake the set empty.N)r)rrrrÚclearÍsz 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|jƒS)N)Úlenr)rrrrÚ__len__ßsz Set.__len__cCs t|jƒS)N)Úiterr)rrrrÚ__iter__âsz Set.__iter__cCs |j|S)N)r)rÚirrrÚ __getitem__åszSet.__getitem__cCs |j|=dS)N)r)rr/rrrÚ __delitem__èszSet.__delitem__cCs4t|tƒstdƒ‚x|jD]}||jkrdSqWdS)z?Is I{self} a subset of I{other}? @rtype: bool zother must be a Set instanceFT)rrr r)rrrrrrÚissubsetës    z Set.issubsetcCs4t|tƒstdƒ‚x|jD]}||jkrdSqWdS)zAIs I{self} a superset of I{other}? @rtype: bool zother must be a Set instanceFT)rrr r)rrrrrrÚ issupersetøs    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)r7ÚobjectrrrrrÚs