HEX
Server: LiteSpeed
System: Linux us-phx-web1284.main-hosting.eu 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: u300739242 (300739242)
PHP: 8.2.30
Disabled: system, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/exabgp/vendoring/__pycache__/counter.cpython-37.pyc
B

RP�e�)�@s dZddlTGdd�de�ZdS)z-
counter.py

From python2.7 standard library
�)�*cs�eZdZdZd!�fdd�	Zdd�Zd"dd�Zd	d
�Zed#dd��Z	d$�fd
d�	Z
d%dd�Zdd�Zdd�Z
�fdd�Zdd�Zdd�Zdd�Zdd�Zdd �Z�ZS)&�Countera�Dict subclass for counting hashable items.  Sometimes called a bag
    or multiset.  Elements are stored as dictionary keys and their counts
    are stored as dictionary values.

    >>> c = Counter('abcdeabcdabcaba')  # count elements from a string

    >>> c.most_common(3)                # three most common elements
    [('a', 5), ('b', 4), ('c', 3)]
    >>> sorted(c)                       # list all unique elements
    ['a', 'b', 'c', 'd', 'e']
    >>> ''.join(sorted(c.elements()))   # list elements with repetitions
    'aaaaabbbbcccdde'
    >>> sum(c.values())                 # total of all counts
    15

    >>> c['a']                          # count of letter 'a'
    5
    >>> for elem in 'shazam':           # update counts from an iterable
    ...     c[elem] += 1                # by adding 1 to each element's count
    >>> c['a']                          # now there are seven 'a'
    7
    >>> del c['b']                      # remove all 'b'
    >>> c['b']                          # now there are zero 'b'
    0

    >>> d = Counter('simsalabim')       # make another counter
    >>> c.update(d)                     # add in the second counter
    >>> c['a']                          # now there are nine 'a'
    9

    >>> c.clear()                       # empty the counter
    >>> c
    Counter()

    Note:  If a count is set to zero or reduced to zero, it will remain
    in the counter until the entry is deleted or the counter is cleared:

    >>> c = Counter('aaabbc')
    >>> c['b'] -= 2                     # reduce the count of 'b' by two
    >>> c.most_common()                 # 'b' is still in, but its count is zero
    [('a', 3), ('c', 1), ('b', 0)]

    Ncs tt|���|j|f|�dS)a	Create a new, empty Counter object.  And if given, count elements
        from an input iterable.  Or, initialize the count from another mapping
        of elements to their counts.

        >>> c = Counter()                           # a new, empty counter
        >>> c = Counter('gallahad')                 # a new counter from an iterable
        >>> c = Counter({'a': 4, 'b': 2})           # a new counter from a mapping
        >>> c = Counter(a=4, b=2)                   # a new counter from keyword args

        N)�superr�__init__�update)�self�iterable�kwds)�	__class__��I/opt/alt/python37/lib/python3.7/site-packages/exabgp/vendoring/counter.pyr?szCounter.__init__cCsdS)z1The count of elements not in the Counter is zero.rr)r�keyrrr�__missing__MszCounter.__missing__cCs6|dkrt|��td�dd�Stj||��td�d�S)z�List the n most common elements and their counts from the most
        common to the least.  If n is None, then list all element counts.

        >>> Counter('abcdeabcdabcaba').most_common(3)
        [('a', 5), ('b', 4), ('c', 3)]

        N�T)r
�reverse)r
)�sorted�	iteritems�_itemgetter�_heapq�nlargest)r�nrrr�most_commonRs	zCounter.most_commoncCst�tt|����S)a�Iterator over elements repeating each as many times as its count.

        >>> c = Counter('ABCABC')
        >>> sorted(c.elements())
        ['A', 'A', 'B', 'B', 'C', 'C']

        # Knuth's example for prime factors of 1836:  2**2 * 3**3 * 17**1
        >>> prime_factors = Counter({2: 2, 3: 3, 17: 1})
        >>> product = 1
        >>> for factor in prime_factors.elements():     # loop over factors
        ...     product *= factor                       # and multiply them
        >>> product
        1836

        Note, if an element's count has been set to zero or is a negative
        number, elements() will ignore it.

        )�_chain�
from_iterable�_starmap�_repeatr)rrrr�elements_szCounter.elementscCstd��dS)Nz@Counter.fromkeys() is undefined.  Use Counter(iterable) instead.)�NotImplementedError)�clsr�vrrr�fromkeyswszCounter.fromkeyscs�|dk	r~t|t�rX|rF|j}x8|��D]\}}||d�|||<q&Wq~tt|��|�n&|j}x|D]}||d�d||<qdW|r�|�|�dS)a�Like dict.update() but add counts instead of replacing them.

        Source can be an iterable, a dictionary, or another Counter instance.

        >>> c = Counter('which')
        >>> c.update('witch')           # add elements from another iterable
        >>> d = Counter('watch')
        >>> c.update(d)                 # add elements from another counter
        >>> c['h']                      # four 'h' in which, witch, and watch
        4

        Nrr)�
isinstance�Mapping�getrrrr)rrr	�self_get�elem�count)r
rrr}s

zCounter.updatecKst|dk	rb|j}t|t�rBxH|��D]\}}||d�|||<q"Wn x|D]}||d�d||<qHW|rp|�|�dS)a�Like dict.update() but subtracts counts instead of replacing them.
        Counts can be reduced below zero.  Both the inputs and outputs are
        allowed to contain zero and negative counts.

        Source can be an iterable, a dictionary, or another Counter instance.

        >>> c = Counter('which')
        >>> c.subtract('witch')             # subtract elements from another iterable
        >>> c.subtract(Counter('watch'))    # subtract elements from another counter
        >>> c['h']                          # 2 in which, minus 1 in witch, minus 1 in watch
        0
        >>> c['w']                          # 1 in which, minus 1 in witch, minus 1 in watch
        -1

        Nrr)r#r!r"�items�subtract)rrr	r$r%r&rrrr(�s

zCounter.subtractcCs
|�|�S)zReturn a shallow copy.)r
)rrrr�copy�szCounter.copycCs|jt|�ffS)N)r
�dict)rrrr�
__reduce__�szCounter.__reduce__cs||krtt|��|�dS)zGLike dict.__delitem__() but does not raise KeyError for missing values.N)rr�__delitem__)rr%)r
rrr,�szCounter.__delitem__cCs6|sd|jjSd�tdj|����}d|jj|fS)Nz%s()z, z%r: %rz%s({%s}))r
�__name__�join�map�__mod__r)rr'rrr�__repr__�szCounter.__repr__cCsxt|t�stSt�}x0|��D]$\}}|||}|dkr|||<qWx,|��D] \}}||krP|dkrP|||<qPW|S)zAdd counts from two counters.

        >>> Counter('abbb') + Counter('bcc')
        Counter({'b': 4, 'c': 2, 'a': 1})

        r)r!r�NotImplementedr')r�other�resultr%r&�newcountrrr�__add__�s
zCounter.__add__cCs|t|t�stSt�}x0|��D]$\}}|||}|dkr|||<qWx0|��D]$\}}||krP|dkrPd|||<qPW|S)z� Subtract count, but keep only results with positive counts.

        >>> Counter('abbbc') - Counter('bccd')
        Counter({'b': 2, 'a': 1})

        r)r!rr2r')rr3r4r%r&r5rrr�__sub__�s
zCounter.__sub__cCs�t|t�stSt�}x<|��D]0\}}||}||kr:|n|}|dkr|||<qWx,|��D] \}}||kr\|dkr\|||<q\W|S)z�Union is the maximum of value in either of the input counters.

        >>> Counter('abbb') | Counter('bcc')
        Counter({'b': 3, 'c': 2, 'a': 1})

        r)r!rr2r')rr3r4r%r&�other_countr5rrr�__or__�s
zCounter.__or__cCsVt|t�stSt�}x<|��D]0\}}||}||kr:|n|}|dkr|||<qW|S)z� Intersection is the minimum of corresponding counts.

        >>> Counter('abbb') & Counter('bcc')
        Counter({'b': 1})

        r)r!rr2r')rr3r4r%r&r8r5rrr�__and__s
zCounter.__and__)N)N)N)N)N)r-�
__module__�__qualname__�__doc__rrrr�classmethodr rr(r)r+r,r1r6r7r9r:�
__classcell__rr)r
rrs"+	

#
rN)r=�_abcollr*rrrrr�<module>s