
    ,hqM                         d Z ddlmZ ddlmZmZmZmZmZm	Z	 ddl
mZ ddlmZmZ 	 ddlmZmZmZ  G d d	ee      Zy
# e$ r ddlmZmZmZ Y w xY w)aE  Sorted Set
=============

:doc:`Sorted Containers<index>` is an Apache2 licensed Python sorted
collections library, written in pure-Python, and fast as C-extensions. The
:doc:`introduction<introduction>` is the best way to get started.

Sorted set implementations:

.. currentmodule:: sortedcontainers

* :class:`SortedSet`

    )chain)eqnegtgeltle)dedent   )
SortedListrecursive_repr)
MutableSetSequenceSetc                      e Zd ZdZd+dZed,d       Zed        Zd Z	d Z
d Zd	 Z eed
d      Z eedd      Z eedd      Z eedd      Z eedd      Z eedd      Z ee      Zd Zd Zd Zd ZeZd Zd Z e Z!d Z"d Z#e#Z$d-dZ%d Z&d  Z'e'Z(d! Z)e)Z*d" Z+e+Z,e,Z-d# Z.e.Z/d$ Z0e0Z1e1Z2d% Z3e3Z4d& Z5e5Z6e6Z7d' Z8e8Z9e8Z:d( Z; e<       d)        Z=d* Z>y).	SortedSeta  Sorted set is a sorted mutable set.

    Sorted set values are maintained in sorted order. The design of sorted set
    is simple: sorted set uses a set for set-operations and maintains a sorted
    list of values.

    Sorted set values must be hashable and comparable. The hash and total
    ordering of values must not change while they are stored in the sorted set.

    Mutable set methods:

    * :func:`SortedSet.__contains__`
    * :func:`SortedSet.__iter__`
    * :func:`SortedSet.__len__`
    * :func:`SortedSet.add`
    * :func:`SortedSet.discard`

    Sequence methods:

    * :func:`SortedSet.__getitem__`
    * :func:`SortedSet.__delitem__`
    * :func:`SortedSet.__reversed__`

    Methods for removing values:

    * :func:`SortedSet.clear`
    * :func:`SortedSet.pop`
    * :func:`SortedSet.remove`

    Set-operation methods:

    * :func:`SortedSet.difference`
    * :func:`SortedSet.difference_update`
    * :func:`SortedSet.intersection`
    * :func:`SortedSet.intersection_update`
    * :func:`SortedSet.symmetric_difference`
    * :func:`SortedSet.symmetric_difference_update`
    * :func:`SortedSet.union`
    * :func:`SortedSet.update`

    Methods for miscellany:

    * :func:`SortedSet.copy`
    * :func:`SortedSet.count`
    * :func:`SortedSet.__repr__`
    * :func:`SortedSet._check`

    Sorted list methods available:

    * :func:`SortedList.bisect_left`
    * :func:`SortedList.bisect_right`
    * :func:`SortedList.index`
    * :func:`SortedList.irange`
    * :func:`SortedList.islice`
    * :func:`SortedList._reset`

    Additional sorted list methods available, if key-function used:

    * :func:`SortedKeyList.bisect_key_left`
    * :func:`SortedKeyList.bisect_key_right`
    * :func:`SortedKeyList.irange_key`

    Sorted set comparisons use subset and superset relations. Two sorted sets
    are equal if and only if every element of each sorted set is contained in
    the other (each is a subset of the other). A sorted set is less than
    another sorted set if and only if the first sorted set is a proper subset
    of the second sorted set (is a subset, but is not equal). A sorted set is
    greater than another sorted set if and only if the first sorted set is a
    proper superset of the second sorted set (is a superset, but is not equal).

    Nc                    || _         t        | d      st               | _        t	        | j                  |      | _        | j                  }|j                  | _        |j                  | _        |j                  | _        | j
                  }|j                  | _	        |j                  | _
        |j                  | _        |j                  | _        |j                  | _        |j                  | _        |j                  | _        |D|j                   | _        |j"                  | _        |j$                  | _        |j&                  | _        || j)                  |       yy)a  Initialize sorted set instance.

        Optional `iterable` argument provides an initial iterable of values to
        initialize the sorted set.

        Optional `key` argument defines a callable that, like the `key`
        argument to Python's `sorted` function, extracts a comparison key from
        each value. The default, none, compares values directly.

        Runtime complexity: `O(n*log(n))`

        >>> ss = SortedSet([3, 1, 2, 5, 4])
        >>> ss
        SortedSet([1, 2, 3, 4, 5])
        >>> from operator import neg
        >>> ss = SortedSet([3, 1, 2, 5, 4], neg)
        >>> ss
        SortedSet([5, 4, 3, 2, 1], key=<built-in function neg>)

        :param iterable: initial values (optional)
        :param key: function used to extract comparison key (optional)

        _setkeyN)_keyhasattrsetr   r   _list
isdisjointissubset
issupersetbisect_leftbisectbisect_rightindexirangeislice_resetbisect_key_leftbisect_key_right
bisect_key
irange_key_update)selfiterabler   r   r   s        \/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/sortedcontainers/sortedset.py__init__zSortedSet.__init__l   s   0 	 tV$DI		s3
 yy//// 

 ,,ll!..[[
llllll?#(#8#8D $)$:$:D!#..DO#..DOLL"      c                 b    t         j                  |       }||_        |j                  |       |S )ztInitialize sorted set from existing set.

        Used internally by set operations that return a new set.

        r   )object__new__r   r-   )clsvaluesr   
sorted_sets       r,   _fromsetzSortedSet._fromset   s0     ^^C(
 
$r.   c                     | j                   S )zFunction used to extract comparison key from values.

        Sorted set compares values directly when the key function is none.

        )r   r*   s    r,   r   zSortedSet.key   s     yyr.   c                     || j                   v S )aQ  Return true if `value` is an element of the sorted set.

        ``ss.__contains__(value)`` <==> ``value in ss``

        Runtime complexity: `O(1)`

        >>> ss = SortedSet([1, 2, 3, 4, 5])
        >>> 3 in ss
        True

        :param value: search for value in sorted set
        :return: true if `value` in sorted set

        r   r*   values     r,   __contains__zSortedSet.__contains__   s     		!!r.   c                      | j                   |   S )a  Lookup value at `index` in sorted set.

        ``ss.__getitem__(index)`` <==> ``ss[index]``

        Supports slicing.

        Runtime complexity: `O(log(n))` -- approximate.

        >>> ss = SortedSet('abcde')
        >>> ss[2]
        'c'
        >>> ss[-1]
        'e'
        >>> ss[2:5]
        ['c', 'd', 'e']

        :param index: integer or slice for indexing
        :return: value or list of values
        :raises IndexError: if index out of range

        )r   )r*   r!   s     r,   __getitem__zSortedSet.__getitem__   s    , zz%  r.   c                     | j                   }| j                  }t        |t              r||   }|j	                  |       ||= y||   }|j                  |       ||= y)a  Remove value at `index` from sorted set.

        ``ss.__delitem__(index)`` <==> ``del ss[index]``

        Supports slicing.

        Runtime complexity: `O(log(n))` -- approximate.

        >>> ss = SortedSet('abcde')
        >>> del ss[2]
        >>> ss
        SortedSet(['a', 'b', 'd', 'e'])
        >>> del ss[:2]
        >>> ss
        SortedSet(['d', 'e'])

        :param index: integer or slice for indexing
        :raises IndexError: if index out of range

        N)r   r   
isinstanceslicedifference_updateremove)r*   r!   r   r   r3   r;   s         r,   __delitem__zSortedSet.__delitem__   s^    * yy

eU#5\F""6* %L %LEKK%Lr.   c                       fd} j                   }dj                  |      |_         d}t        |j                  |||            |_        |S )zMake comparator method.c                     t        |t              r | j                  |j                        S t        |t              r | j                  |      S t        S )z&Compare method for sorted set and set.)r@   r   r   r   NotImplemented)r*   otherset_ops     r,   comparerz&SortedSet.__make_cmp.<locals>.comparer  sC    %+dii44E3'dii//!!r.   z__{0}__a3  Return true if and only if sorted set is {0} `other`.

        ``ss.__{1}__(other)`` <==> ``ss {2} other``

        Comparisons use subset and superset semantics as with sets.

        Runtime complexity: `O(n)`

        :param other: `other` set
        :return: true if sorted set is {0} `other`

        )__name__formatr
   __doc__)rI   symboldocrJ   set_op_namedoc_strs   `     r,   
__make_cmpzSortedSet.__make_cmp  sN    	" oo%,,[9 "'..k6"JKr.   z==zequal toz!=znot equal to<za proper subset of>za proper superset ofz<=za subset ofz>=za superset ofc                 ,    t        | j                        S )z|Return the size of the sorted set.

        ``ss.__len__()`` <==> ``len(ss)``

        :return: size of sorted set

        )lenr   r7   s    r,   __len__zSortedSet.__len__2  s     499~r.   c                 ,    t        | j                        S )zReturn an iterator over the sorted set.

        ``ss.__iter__()`` <==> ``iter(ss)``

        Iterating the sorted set while adding or deleting values may raise a
        :exc:`RuntimeError` or fail to iterate over all values.

        )iterr   r7   s    r,   __iter__zSortedSet.__iter__=  s     DJJr.   c                 ,    t        | j                        S )zReturn a reverse iterator over the sorted set.

        ``ss.__reversed__()`` <==> ``reversed(ss)``

        Iterating the sorted set while adding or deleting values may raise a
        :exc:`RuntimeError` or fail to iterate over all values.

        )reversedr   r7   s    r,   __reversed__zSortedSet.__reversed__I  s     

##r.   c                 ~    | j                   }||vr-|j                  |       | j                  j                  |       yy)a  Add `value` to sorted set.

        Runtime complexity: `O(log(n))` -- approximate.

        >>> ss = SortedSet()
        >>> ss.add(3)
        >>> ss.add(1)
        >>> ss.add(2)
        >>> ss
        SortedSet([1, 2, 3])

        :param value: value to add to sorted set

        N)r   addr   r*   r;   r   s      r,   r_   zSortedSet.addU  s5     yyHHUOJJNN5! r.   c                 l    | j                   j                          | j                  j                          y)zPRemove all values from sorted set.

        Runtime complexity: `O(n)`

        N)r   clearr   r7   s    r,   rb   zSortedSet.clearl  s"     			

r.   c                 b    | j                  t        | j                        | j                        S )zwReturn a shallow copy of the sorted set.

        Runtime complexity: `O(n)`

        :return: new sorted set

        r   )r5   r   r   r   r7   s    r,   copyzSortedSet.copyv  s#     }}S^};;r.   c                 &    || j                   v rdS dS )a  Return number of occurrences of `value` in the sorted set.

        Runtime complexity: `O(1)`

        >>> ss = SortedSet([1, 2, 3, 4, 5])
        >>> ss.count(3)
        1

        :param value: value to count in sorted set
        :return: count

        r   r   r9   r:   s     r,   countzSortedSet.count  s     TYY&q-A-r.   c                 ~    | j                   }||v r-|j                  |       | j                  j                  |       yy)aq  Remove `value` from sorted set if it is a member.

        If `value` is not a member, do nothing.

        Runtime complexity: `O(log(n))` -- approximate.

        >>> ss = SortedSet([1, 2, 3, 4, 5])
        >>> ss.discard(5)
        >>> ss.discard(0)
        >>> ss == set([1, 2, 3, 4])
        True

        :param value: `value` to discard from sorted set

        Nr   rC   r   r`   s      r,   discardzSortedSet.discard  s7      yyD=KKJJe$ r.   c                 r    | j                   j                  |      }| j                  j                  |       |S )a  Remove and return value at `index` in sorted set.

        Raise :exc:`IndexError` if the sorted set is empty or index is out of
        range.

        Negative indices are supported.

        Runtime complexity: `O(log(n))` -- approximate.

        >>> ss = SortedSet('abcde')
        >>> ss.pop()
        'e'
        >>> ss.pop(2)
        'c'
        >>> ss
        SortedSet(['a', 'b', 'd'])

        :param int index: index of value (default -1)
        :return: value
        :raises IndexError: if index is out of range

        )r   popr   rC   )r*   r!   r;   s      r,   rk   zSortedSet.pop  s-    0 

u%		r.   c                 p    | j                   j                  |       | j                  j                  |       y)a  Remove `value` from sorted set; `value` must be a member.

        If `value` is not a member, raise :exc:`KeyError`.

        Runtime complexity: `O(log(n))` -- approximate.

        >>> ss = SortedSet([1, 2, 3, 4, 5])
        >>> ss.remove(5)
        >>> ss == set([1, 2, 3, 4])
        True
        >>> ss.remove(0)
        Traceback (most recent call last):
          ...
        KeyError: 0

        :param value: `value` to remove from sorted set
        :raises KeyError: if `value` is not in sorted set

        Nrh   r:   s     r,   rC   zSortedSet.remove  s(    ( 			

% r.   c                 n     | j                   j                  | }| j                  || j                        S )a  Return the difference of two or more sets as a new sorted set.

        The `difference` method also corresponds to operator ``-``.

        ``ss.__sub__(iterable)`` <==> ``ss - iterable``

        The difference is all values that are in this sorted set but not the
        other `iterables`.

        >>> ss = SortedSet([1, 2, 3, 4, 5])
        >>> ss.difference([4, 5, 6, 7])
        SortedSet([1, 2, 3])

        :param iterables: iterable arguments
        :return: new sorted set

        r   )r   
differencer5   r   )r*   	iterablesdiffs      r,   rn   zSortedSet.difference  s1    $ $tyy##Y/}}Ttyy}11r.   c                 *   | j                   }| j                  }t        t        |       }dt	        |      z  t	        |      kD  r4|j                  |       |j                          |j                  |       | S | j                  }|D ]
  } ||        | S )a  Remove all values of `iterables` from this sorted set.

        The `difference_update` method also corresponds to operator ``-=``.

        ``ss.__isub__(iterable)`` <==> ``ss -= iterable``

        >>> ss = SortedSet([1, 2, 3, 4, 5])
        >>> _ = ss.difference_update([4, 5, 6, 7])
        >>> ss
        SortedSet([1, 2, 3])

        :param iterables: iterable arguments
        :return: itself

           )	r   r   r   r   rV   rB   rb   update_discard)r*   ro   r   r   r3   rt   r;   s          r,   rB   zSortedSet.difference_update  s      yy

UI&'FOs4y(""6*KKMLL
  }}H   r.   c                 n     | j                   j                  | }| j                  || j                        S )a  Return the intersection of two or more sets as a new sorted set.

        The `intersection` method also corresponds to operator ``&``.

        ``ss.__and__(iterable)`` <==> ``ss & iterable``

        The intersection is all values that are in this sorted set and each of
        the other `iterables`.

        >>> ss = SortedSet([1, 2, 3, 4, 5])
        >>> ss.intersection([4, 5, 6, 7])
        SortedSet([4, 5])

        :param iterables: iterable arguments
        :return: new sorted set

        r   )r   intersectionr5   r   )r*   ro   	intersects      r,   rv   zSortedSet.intersection  s1    $ +DII**I6	}}YDII}66r.   c                     | j                   }| j                  } |j                  |  |j                          |j	                  |       | S )a  Update the sorted set with the intersection of `iterables`.

        The `intersection_update` method also corresponds to operator ``&=``.

        ``ss.__iand__(iterable)`` <==> ``ss &= iterable``

        Keep only values found in itself and all `iterables`.

        >>> ss = SortedSet([1, 2, 3, 4, 5])
        >>> _ = ss.intersection_update([4, 5, 6, 7])
        >>> ss
        SortedSet([4, 5])

        :param iterables: iterable arguments
        :return: itself

        )r   r   intersection_updaterb   rs   )r*   ro   r   r   s       r,   ry   zSortedSet.intersection_update1  s@    $ yy

   ),Tr.   c                 r    | j                   j                  |      }| j                  || j                        S )a  Return the symmetric difference with `other` as a new sorted set.

        The `symmetric_difference` method also corresponds to operator ``^``.

        ``ss.__xor__(other)`` <==> ``ss ^ other``

        The symmetric difference is all values tha are in exactly one of the
        sets.

        >>> ss = SortedSet([1, 2, 3, 4, 5])
        >>> ss.symmetric_difference([4, 5, 6, 7])
        SortedSet([1, 2, 3, 6, 7])

        :param other: `other` iterable
        :return: new sorted set

        r   )r   symmetric_differencer5   r   )r*   rH   rp   s      r,   r{   zSortedSet.symmetric_differenceM  s/    $ yy--e4}}Ttyy}11r.   c                     | j                   }| j                  }|j                  |       |j                          |j	                  |       | S )a  Update the sorted set with the symmetric difference with `other`.

        The `symmetric_difference_update` method also corresponds to operator
        ``^=``.

        ``ss.__ixor__(other)`` <==> ``ss ^= other``

        Keep only values found in exactly one of itself and `other`.

        >>> ss = SortedSet([1, 2, 3, 4, 5])
        >>> _ = ss.symmetric_difference_update([4, 5, 6, 7])
        >>> ss
        SortedSet([1, 2, 3, 6, 7])

        :param other: `other` iterable
        :return: itself

        )r   r   symmetric_difference_updaterb   rs   )r*   rH   r   r   s       r,   r}   z%SortedSet.symmetric_difference_updatef  s>    & yy

((/Tr.   c                 b    | j                  t        t        |       g| | j                        S )a  Return new sorted set with values from itself and all `iterables`.

        The `union` method also corresponds to operator ``|``.

        ``ss.__or__(iterable)`` <==> ``ss | iterable``

        >>> ss = SortedSet([1, 2, 3, 4, 5])
        >>> ss.union([4, 5, 6, 7])
        SortedSet([1, 2, 3, 4, 5, 6, 7])

        :param iterables: iterable arguments
        :return: new sorted set

        r   )	__class__r   rY   r   )r*   ro   s     r,   unionzSortedSet.union  s)     ~~eDJ;;~KKr.   c                 B   | j                   }| j                  }t        t        |       }dt	        |      z  t	        |      kD  r@| j                  }|j                  |       |j                          |j                  |       | S | j                  }|D ]
  } ||        | S )a  Update the sorted set adding values from all `iterables`.

        The `update` method also corresponds to operator ``|=``.

        ``ss.__ior__(iterable)`` <==> ``ss |= iterable``

        >>> ss = SortedSet([1, 2, 3, 4, 5])
        >>> _ = ss.update([4, 5, 6, 7])
        >>> ss
        SortedSet([1, 2, 3, 4, 5, 6, 7])

        :param iterables: iterable arguments
        :return: itself

        rr   )r   r   r   r   rV   rs   rb   _add)r*   ro   r   r   r3   r   r;   s          r,   rs   zSortedSet.update  s      yy

UI&'FOs4y(JJEKKKKMLL
  99D Ur.   c                 H    t        |       | j                  | j                  ffS )zSupport for pickle.

        The tricks played with exposing methods in :func:`SortedSet.__init__`
        confuse pickle so customize the reducer.

        )typer   r   r7   s    r,   
__reduce__zSortedSet.__reduce__  s      T
TYY		233r.   c                     | j                   }|dndj                  |      }t        |       j                  }dj                  |t	        |       |      S )zReturn string representation of sorted set.

        ``ss.__repr__()`` <==> ``repr(ss)``

        :return: string representation

         z, key={0!r}z{0}({1!r}{2}))r   rL   r   rK   list)r*   r   r   	type_names       r,   __repr__zSortedSet.__repr__  sK     yyLbm&:&:4&@J''	%%idSAAr.   c                     | j                   | j                  }|j                          t              t        |      k(  sJ t	        fd|D              sJ y)zMCheck invariants of sorted set.

        Runtime complexity: `O(n)`

        c              3   &   K   | ]  }|v  
 y wN ).0r;   r   s     r,   	<genexpr>z#SortedSet._check.<locals>.<genexpr>  s     4U5D=4s   N)r   r   _checkrV   all)r*   r   r   s     @r,   r   zSortedSet._check  sG     yy

4yCJ&&4e4444r.   )NNr   ))?rK   
__module____qualname__rM   r-   classmethodr5   propertyr   r<   r>   rD   _SortedSet__make_cmpr   __eq__r   __ne__r   __lt__r   __gt__r	   __le__r   __ge__staticmethodrW   rZ   r]   r_   r   rb   rd   __copy__rf   ri   rt   rk   rC   rn   __sub__rB   __isub__rv   __and____rand__ry   __iand__r{   __xor____rxor__r}   __ixor__r   __or____ror__rs   __ior__r)   r   r   r   r   r   r.   r,   r   r   $   s   FN<#~ 	 	  "$!2@8 D*-FD.1FC!56FC!78FD-0FD/2Fj)J	 	$"( D< H. %* H:!02* G: !H7* GH2 #H2* #GH4 +HL" FG< GG4 B B
5r.   r   N)rM   	itertoolsr   operatorr   r   r   r   r   r	   textwrapr
   
sortedlistr   r   collections.abcr   r   r   ImportErrorcollectionsr   r   r.   r,   <module>r      sM     + +  2699y
5
H y
5  6556s   
? AA