n9e0ddlmZmZmZmZddlmZddlmZm Z ddl m Z e ddZ dZ Gd d ee Zejeejeejeejed Zd Zee Zy )) ContainerIterableSizedHashable)reduce)GenericTypeVar)pmapT_coT) covariantcL|j||j|ddzS)Nr)setget)counterselements 2/usr/lib/python3/dist-packages/pyrsistent/_pbag.py_add_to_countersr s# <<gq!9A!= >>ceZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZeZeZeZdZdZdZdZdZy)PBaga A persistent bag/multiset type. Requires elements to be hashable, and allows duplicates, but has no ordering. Bags are hashable. Do not instantiate directly, instead use the factory functions :py:func:`b` or :py:func:`pbag` to create an instance. Some examples: >>> s = pbag([1, 2, 3, 1]) >>> s2 = s.add(4) >>> s3 = s2.remove(1) >>> s pbag([1, 1, 2, 3]) >>> s2 pbag([1, 1, 2, 3, 4]) >>> s3 pbag([1, 2, 3, 4]) )_counts __weakref__c||_y)Nr)selfcountss r__init__z PBag.__init__&s  rc@tt|j|S)z Add an element to the bag. >>> s = pbag([1]) >>> s2 = s.add(1) >>> s3 = s.add(2) >>> s2 pbag([1, 1]) >>> s3 pbag([1, 2]) )rrrrrs raddzPBag.add)s$T\\7;<>> s = pbag([1]) >>> s.update([1, 2]) pbag([1, 1, 2]) )rrrr)riterables rupdatez PBag.update7s% /4<<HI I rc||jvr t||j|dk(r&|jj|}t |S|jj||j|dz }t |S)z Remove an element from the bag. >>> s = pbag([1, 1, 2]) >>> s2 = s.remove(1) >>> s3 = s.remove(2) >>> s2 pbag([1, 2]) >>> s3 pbag([1, 1]) r)rKeyErrorremoverr)rrnewcs rr'z PBag.removeDs| $,, &7# # \\' "a '<<&&w/DDz<<##GT\\'-BQ-FGDDzrc:|jj|dS)z Return the number of times an element appears. >>> pbag([]).count('non-existent') 0 >>> pbag([1, 1, 2]).count(1) 2 r)rrr s rcountz PBag.countXs||++rcHt|jjS)ze Return the length including duplicates. >>> len(pbag([1, 1, 2])) 3 )sumr itervaluesrs r__len__z PBag.__len__ds4<<**,--rc#xK|jjD]\}}t|D]}|yw)z Return an iterator of all elements, including duplicates. >>> list(pbag([1, 1, 2])) [1, 1, 2] >>> list(pbag([1, 2])) [1, 2] N)r iteritemsrange)reltr*is r__iter__z PBag.__iter__ms@,,002 JC5\    s8:c||jvS)z Check if an element is in the bag. >>> 1 in pbag([1, 1, 2]) True >>> 0 in pbag([1, 2]) False r)rr3s r __contains__zPBag.__contains__zsdll""rc6djt|S)Nz pbag({0}))formatlistr.s r__repr__z PBag.__repr__s!!$t*--rclt|tur td|j|jk(S)z Check if two bags are equivalent, honoring the number of duplicates, and ignoring insertion order. >>> pbag([1, 1, 2]) == pbag([1, 2]) False >>> pbag([2, 1, 0]) == pbag([0, 1, 2]) True z Can only compare PBag with PBags)typer TypeErrorrrothers r__eq__z PBag.__eq__s/ ;d ">? ?||u}},,rctd)NzPBags are not orderable)r>r?s r__lt__z PBag.__lt__s122rct|tstS|jj }|jj D]\}}|j ||z||<t|jS)z Combine elements from two PBags. >>> pbag([1, 2, 2]) + pbag([2, 3, 3]) pbag([1, 2, 2, 2, 3, 3]) ) isinstancerNotImplementedrevolverr1r* persistent)rr@resultelem other_counts r__add__z PBag.__add__sr%&! !%%'!&!8!8!: : D+::d+k9F4L :F%%'((rcBt|tstS|jj }|jj D]:\}}|j ||z }|dkDr|||<%||vs*|j|<t|jS)z Remove elements from one PBag that are present in another. >>> pbag([1, 2, 2, 2, 3]) - pbag([2, 3, 3, 4]) pbag([1, 2, 2]) r) rErrFrrGr1r*r'rH)rr@rIrJrKnewcounts r__sub__z PBag.__sub__s%&! !%%'!&!8!8!: $ D+zz$'+5H!|'t  d#  $ F%%'((rct|tstS|jj }|jj D]'\}}|j |}t||}|||<)t|jS)z Union: Keep elements that are present in either of two PBags. >>> pbag([1, 2, 2, 2]) | pbag([2, 3, 3]) pbag([1, 2, 2, 2, 3, 3]) ) rErrFrrGr1r*maxrH)rr@rIrJrKr*rNs r__or__z PBag.__or__s%&! !%%'!&!8!8!: $ D+JJt$E5+.H#F4L $F%%'((rc t|tstStj }|j j D]+\}}t||j|}|dkDs'|||<-t|jS)z Intersection: Only keep elements that are present in both PBags. >>> pbag([1, 2, 2, 2]) & pbag([2, 3, 3]) pbag([2]) r) rErrFr rGrr1minr*rH)rr@rIrJr*rNs r__and__z PBag.__and__s}%&! !!<<113 (KD%5%++d"34H!|'t  (F%%'((rc,t|jS)z Hash based on value of elements. >>> m = pmap({pbag([1, 2]): "it's here!"}) >>> m[pbag([2, 1])] "it's here!" >>> pbag([1, 1, 2]) in m False )hashrr.s r__hash__z PBag.__hash__sDLL!!rN)__name__ __module__ __qualname____doc__ __slots__rr!r$r'r*r/r5r7r;rArC__le____gt____ge__rLrOrRrUrXrrrr so,+I = ( ,.  #. -3F F F ))$) ) "rrct|S)z Construct a persistent bag. Takes an arbitrary number of arguments to insert into the new persistent bag. >>> b(1, 2, 3, 2) pbag([1, 2, 2, 3]) )pbagelementss rbrfs >rcV|stSttt|t S)z Convert an iterable to a persistent bag. Takes an iterable with elements to insert. >>> pbag([1, 2, 3, 2]) pbag([1, 2, 2, 3]) ) _EMPTY_PBAGrrrr rds rrcrcs$  '46: ;;rN)collections.abcrrrr functoolsrtypingrr pyrsistent._pmapr r rrregisterrfrcrhrarrrns@@#!v&?\"74=\"~ 4$t$  <46l r