nfc@sdZddlmZmZdddgZddlZejdedd defd YZ de fd YZ de fd YZ d e fdYZ dS(sClasses to represent arbitrary sets (including sets of sets). This module implements sets using dictionaries whose values are ignored. The usual operations (union, intersection, deletion, etc.) are provided as both methods and operators. Important: sets are not sequences! While they support 'x in s', 'len(s)', and 'for x in s', none of those operations are unique for sequences; for example, mappings support all three as well. The characteristic operation for sequences is subscripting with small integers: s[i], for i in range(len(s)). Sets don't support subscripting at all. Also, sequences allow multiple occurrences and their elements have a definite order; sets on the other hand don't record multiple occurrences and don't remember the order of element insertion (which is why they don't support s[i]). The following classes are provided: BaseSet -- All the operations common to both mutable and immutable sets. This is an abstract class, not meant to be directly instantiated. Set -- Mutable sets, subclass of BaseSet; not hashable. ImmutableSet -- Immutable sets, subclass of BaseSet; hashable. An iterable argument is mandatory to create an ImmutableSet. _TemporarilyImmutableSet -- A wrapper around a Set, hashable, giving the same hash value as the immutable set equivalent would have. Do not use this class directly. Only hashable objects can be added to a Set. In particular, you cannot really add a Set as an element to another Set; if you try, what is actually added is an ImmutableSet built from it (it compares equal to the one you tried adding). When you ask if `x in y' where x is a Set and y is a Set or ImmutableSet, x is wrapped into a _TemporarilyImmutableSet z, and what's tested is actually `z in y'. i(tifiltert ifilterfalsetBaseSettSett ImmutableSetNsthe sets module is deprecatedt stacklevelicBs"eZdZdgZdZdZdZeZedZ dZ dZ dZ d Z d ZeZd Zd Zd ZdZdZdZdZdZdZdZdZdZeZeZdZdZdZ!dZ"dZ#dZ$RS(s1Common base class for mutable and immutable sets.t_datacCs|jtkrtdndS(sThis is an abstract class.s7BaseSet is an abstract class. Use Set or ImmutableSet.N(t __class__Rt TypeError(tself((s/usr/lib64/python2.7/sets.pyt__init__HscCs t|jS(s'Return the number of elements of a set.(tlenR(R ((s/usr/lib64/python2.7/sets.pyt__len__QscCs |jS(seReturn string representation of a set. This looks like 'Set([])'. (t_repr(R ((s/usr/lib64/python2.7/sets.pyt__repr__UscCs6|jj}|r"|jnd|jj|fS(Ns%s(%r)(RtkeystsortRt__name__(R tsortedtelements((s/usr/lib64/python2.7/sets.pyR _s cCs |jjS(ssReturn an iterator over the elements or a set. This is the keys iterator for the underlying dict. (Rtiterkeys(R ((s/usr/lib64/python2.7/sets.pyt__iter__escCs tddS(Nscan't compare sets using cmp()(R(R tother((s/usr/lib64/python2.7/sets.pyt__cmp__qscCs't|tr|j|jkStSdS(N(t isinstanceRRtFalse(R R((s/usr/lib64/python2.7/sets.pyt__eq__scCs't|tr|j|jkStSdS(N(RRRtTrue(R R((s/usr/lib64/python2.7/sets.pyt__ne__scCs#|j}|jj|j|S(sReturn a shallow copy of a set.(RRtupdate(R tresult((s/usr/lib64/python2.7/sets.pytcopys cCscddlm}|j}||t|<|j}t}x!|D]}|||||(R R((s/usr/lib64/python2.7/sets.pyt__lt__7s cCs2|j|t|t|ko1|j|S(N(R=R R?(R R((s/usr/lib64/python2.7/sets.pyt__gt__;s cCst|tstdndS(Ns,Binary operation only permitted between sets(RRR(R R((s/usr/lib64/python2.7/sets.pyR=DscCs+d}x|D]}|t|N}q W|S(Ni(thash(R RR%((s/usr/lib64/python2.7/sets.pyt _compute_hashJs cCs9|j}t|tr,|j|jdSt}t|tttfkrt |}xtry#x|D]}|||R?t__le__t__ge__R@RAR:t__hash__R=RCR*(((s/usr/lib64/python2.7/sets.pyRAsB                  cBs>eZdZdgZddZdZdZdZRS(sImmutable set class.t _hashcodecCs2d|_i|_|dk r.|j|ndS(s5Construct an immutable set from an optional iterable.N(R:RTRR*(R RJ((s/usr/lib64/python2.7/sets.pyR s   cCs(|jdkr!|j|_n|jS(N(RTR:RC(R ((s/usr/lib64/python2.7/sets.pyRSscCs|j|jfS(N(RRT(R ((s/usr/lib64/python2.7/sets.pyt __getstate__scCs|\|_|_dS(N(RRT(R tstate((s/usr/lib64/python2.7/sets.pyt __setstate__sN( RRLRMRNR:R RSRURW(((s/usr/lib64/python2.7/sets.pyRzs     cBseZdZgZddZdZdZdZdZ dZ dZ dZ d Z d Zd Zd Zd ZdZdZdZdZdZdZRS(s Mutable set class.cCs)i|_|dk r%|j|ndS(s*Construct a set from an optional iterable.N(RR:R*(R RJ((s/usr/lib64/python2.7/sets.pyR s  cCs |jfS(N(R(R ((s/usr/lib64/python2.7/sets.pyRUscCs|\|_dS(N(R(R R#((s/usr/lib64/python2.7/sets.pyRWscCs$|j||jj|j|S(s2Update a set with the union of itself and another.(R=RR(R R((s/usr/lib64/python2.7/sets.pyt__ior__s cCs|j|dS(s2Update a set with the union of itself and another.N(R*(R R((s/usr/lib64/python2.7/sets.pyt union_updatescCs!|j|||@j|_|S(s9Update a set with the intersection of itself and another.(R=R(R R((s/usr/lib64/python2.7/sets.pyt__iand__s cCs5t|tr||M}n|j|j|_dS(s9Update a set with the intersection of itself and another.N(RRR+R(R R((s/usr/lib64/python2.7/sets.pytintersection_updates cCs|j||j||S(sAUpdate a set with the symmetric difference of itself and another.(R=tsymmetric_difference_update(R R((s/usr/lib64/python2.7/sets.pyt__ixor__s  cCs{|j}t}t|ts-t|}n||krF|jnx.|D]&}||kri||=qM|||)s :