
    ,hX                         d Z ddlZddlZddlmZ ddlmZmZ ddlm	Z	 	 ddl
mZmZmZmZmZ  G d d	e      Zd
 Z G d dee      Z G d dee      Z G d dee      Zy# e$ r ddlmZmZmZmZmZ Y Hw xY w)a  Sorted Dict
==============

: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 dict implementations:

.. currentmodule:: sortedcontainers

* :class:`SortedDict`
* :class:`SortedKeysView`
* :class:`SortedItemsView`
* :class:`SortedValuesView`

    N)chain   )
SortedListrecursive_repr	SortedSet)	ItemsViewKeysViewMapping
ValuesViewSequencec                      e Zd ZdZd Zed        Zed        Zd Zd Z	d Z
d Zd	 ZeZd
 Zd Zd Zd ZeZed(d       Zd Zd Zd Zej2                  dk  r9d Z edd      Z edd      Z edd      Z edd      Z edd      Z edd      Z  G d de!      Z" e"       Z#e#fd Z$d)d!Z%d)d"Z&d(d#Z'd$ Z(e(Z)d% Z* e+       d&        Z,d' Z-y)*
SortedDicta  Sorted dict is a sorted mutable mapping.

    Sorted dict keys are maintained in sorted order. The design of sorted dict
    is simple: sorted dict inherits from dict to store items and maintains a
    sorted list of keys.

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

    Mutable mapping methods:

    * :func:`SortedDict.__getitem__` (inherited from dict)
    * :func:`SortedDict.__setitem__`
    * :func:`SortedDict.__delitem__`
    * :func:`SortedDict.__iter__`
    * :func:`SortedDict.__len__` (inherited from dict)

    Methods for adding items:

    * :func:`SortedDict.setdefault`
    * :func:`SortedDict.update`

    Methods for removing items:

    * :func:`SortedDict.clear`
    * :func:`SortedDict.pop`
    * :func:`SortedDict.popitem`

    Methods for looking up items:

    * :func:`SortedDict.__contains__` (inherited from dict)
    * :func:`SortedDict.get` (inherited from dict)
    * :func:`SortedDict.peekitem`

    Methods for views:

    * :func:`SortedDict.keys`
    * :func:`SortedDict.items`
    * :func:`SortedDict.values`

    Methods for miscellany:

    * :func:`SortedDict.copy`
    * :func:`SortedDict.fromkeys`
    * :func:`SortedDict.__reversed__`
    * :func:`SortedDict.__eq__` (inherited from dict)
    * :func:`SortedDict.__ne__` (inherited from dict)
    * :func:`SortedDict.__repr__`
    * :func:`SortedDict._check`

    Sorted list methods available (applies to keys):

    * :func:`SortedList.bisect_left`
    * :func:`SortedList.bisect_right`
    * :func:`SortedList.count`
    * :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 dicts may only be compared for equality and inequality.

    c                 *   |r%|d   t        |d         r|d   x}| _        |dd }n	dx}| _        t        |      | _        | j                  }|j                  | _        |j                  | _        |j                  | _	        |j                  | _        |j                  | _        |j                  | _        |j                   | _        |j$                  | _        |j&                  | _        |j&                  | _        |j*                  | _        |j,                  | _        |j.                  | _        |j0                  | _        |D|j2                  | _        |j4                  | _        |j6                  | _        |j8                  | _         | j:                  |i | y)aQ  Initialize sorted dict instance.

        Optional key-function argument defines a callable that, like the `key`
        argument to the built-in `sorted` function, extracts a comparison key
        from each dictionary key. If no function is specified, the default
        compares the dictionary keys directly. The key-function argument must
        be provided as a positional argument and must come before all other
        arguments.

        Optional iterable argument provides an initial sequence of pairs to
        initialize the sorted dict. Each pair in the sequence defines the key
        and corresponding value. If a key is seen more than once, the last
        value associated with it is stored in the new sorted dict.

        Optional mapping argument provides an initial mapping of items to
        initialize the sorted dict.

        If keyword arguments are given, the keywords themselves, with their
        associated values, are added as items to the dictionary. If a key is
        specified both in the positional argument and as a keyword argument,
        the value associated with the keyword is stored in the
        sorted dict.

        Sorted dict keys must be hashable, per the requirement for Python's
        dictionaries. Keys (or the result of the key-function) must also be
        comparable, per the requirement for sorted lists.

        >>> d = {'alpha': 1, 'beta': 2}
        >>> SortedDict([('alpha', 1), ('beta', 2)]) == d
        True
        >>> SortedDict({'alpha': 1, 'beta': 2}) == d
        True
        >>> SortedDict(alpha=1, beta=2) == d
        True

        r   Nr   )key)callable_keyr   _listadd	_list_addclear_list_clear__iter__
_list_iter__reversed___list_reversedpop	_list_popremove_list_removeupdate_list_updatebisect_leftbisect_rightbisectindexirangeislice_resetbisect_key_leftbisect_key_right
bisect_key
irange_key_update)selfargskwargsr   r   s        ]/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/sortedcontainers/sorteddict.py__init__zSortedDict.__init__q   sR   J T!W_a(9#Aw&D498D##D49D)

 

 ;;..#00!LL!LL !,,((!..[[
llllll#(#8#8D $)$:$:D!#..DO#..DOd%f%    c                     | j                   S )zFunction used to extract comparison key from keys.

        Sorted dict compares keys directly when the key function is none.

        )r   r/   s    r2   r   zSortedDict.key   s     yyr4   c                     	 | j                   S # t        $ r3 t        j                  dt        d       t        |       x}| _         |cY S w xY w)zCached reference of sorted keys view.

        Deprecated in version 2 of Sorted Containers. Use
        :func:`SortedDict.keys` instead.

        z>sorted_dict.iloc is deprecated. Use SortedDict.keys() instead.   )
stacklevel)_ilocAttributeErrorwarningswarnDeprecationWarningSortedKeysView)r/   r:   s     r2   iloczSortedDict.iloc   sO    
	:: 	MM2"	 "0!55EDJL	s    9A
	A
c                 N    t         j                  |        | j                          y)zPRemove all items from sorted dict.

        Runtime complexity: `O(n)`

        N)dictr   r   r6   s    r2   r   zSortedDict.clear   s     	

4r4   c                 R    t         j                  | |       | j                  |       y)a  Remove item from sorted dict identified by `key`.

        ``sd.__delitem__(key)`` <==> ``del sd[key]``

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

        >>> sd = SortedDict({'a': 1, 'b': 2, 'c': 3})
        >>> del sd['b']
        >>> sd
        SortedDict({'a': 1, 'c': 3})
        >>> del sd['z']
        Traceback (most recent call last):
          ...
        KeyError: 'z'

        :param key: `key` for item lookup
        :raises KeyError: if key not found

        N)rB   __delitem__r    )r/   r   s     r2   rD   zSortedDict.__delitem__   s"    ( 	s##r4   c                 "    | j                         S )zReturn an iterator over the keys of the sorted dict.

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

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

        )r   r6   s    r2   r   zSortedDict.__iter__   s       r4   c                 "    | j                         S )a  Return a reverse iterator over the keys of the sorted dict.

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

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

        )r   r6   s    r2   r   zSortedDict.__reversed__  s     ""$$r4   c                 \    || vr| j                  |       t        j                  | ||       y)a  Store item in sorted dict with `key` and corresponding `value`.

        ``sd.__setitem__(key, value)`` <==> ``sd[key] = value``

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

        >>> sd = SortedDict()
        >>> sd['c'] = 3
        >>> sd['a'] = 1
        >>> sd['b'] = 2
        >>> sd
        SortedDict({'a': 1, 'b': 2, 'c': 3})

        :param key: key for item
        :param value: value for item

        N)r   rB   __setitem__)r/   r   values      r2   rH   zSortedDict.__setitem__  s)    $ d?NN3sE*r4   c                     t        |t              st        S t        | j	                         |j	                               }| j                  | j                  |      S N
isinstancer   NotImplementedr   items	__class__r   r/   otherrO   s      r2   __or__zSortedDict.__or__1  s?    %)!!djjlEKKM2~~dii//r4   c                     t        |t              st        S t        |j	                         | j	                               }| j                  | j                  |      S rK   rL   rQ   s      r2   __ror__zSortedDict.__ror__8  s?    %)!!ekkmTZZ\2~~dii//r4   c                 (    | j                  |       | S rK   )r.   )r/   rR   s     r2   __ior__zSortedDict.__ior__?  s    Ur4   c                 V    | j                  | j                  | j                               S )zyReturn a shallow copy of the sorted dict.

        Runtime complexity: `O(n)`

        :return: new sorted dict

        )rP   r   rO   r6   s    r2   copyzSortedDict.copyD  s     ~~dii66r4   Nc                 &     | fd|D              S )zReturn a new sorted dict initailized from `iterable` and `value`.

        Items in the sorted dict have keys from `iterable` and values equal to
        `value`.

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

        :return: new sorted dict

        c              3   &   K   | ]  }|f 
 y wrK    ).0r   rI   s     r2   	<genexpr>z&SortedDict.fromkeys.<locals>.<genexpr>]  s     4CC<4   r\   )clsiterablerI   s     `r2   fromkeyszSortedDict.fromkeysQ  s     48444r4   c                     t        |       S )zReturn new sorted keys view of the sorted dict's keys.

        See :class:`SortedKeysView` for details.

        :return: new sorted keys view

        )r?   r6   s    r2   keyszSortedDict.keys`  s     d##r4   c                     t        |       S )zReturn new sorted items view of the sorted dict's items.

        See :class:`SortedItemsView` for details.

        :return: new sorted items view

        )SortedItemsViewr6   s    r2   rO   zSortedDict.itemsk  s     t$$r4   c                     t        |       S )zReturn new sorted values view of the sorted dict's values.

        See :class:`SortedValuesView` for details.

        :return: new sorted values view

        )SortedValuesViewr6   s    r2   valueszSortedDict.valuesv  s      %%r4   i   c                 f    dj                  | |      fd}| |_        |_        t        |      S )NzQSortedDict.{original}() is not implemented. Use SortedDict.{alternate}() instead.)original	alternatec                     t              rK   )r;   )r/   messages    r2   methodz6SortedDict.__make_raise_attributeerror.<locals>.method  s    $W--r4   )format__name____doc__property)rk   rl   ro   rn   s      @r2   __make_raise_attributeerrorz&SortedDict.__make_raise_attributeerror  s;    9fh)f< . 'FO$FNF##r4   	iteritemsrO   iterkeysrd   
itervaluesri   	viewitemsviewkeys
viewvaluesc                       e Zd Zd Zy)SortedDict._NotGivenc                      y)Nz<not-given>r\   r6   s    r2   __repr__zSortedDict._NotGiven.__repr__  s     r4   N)rq   
__module____qualname__r~   r\   r4   r2   	_NotGivenr|     s    	!r4   r   c                     || v r'| j                  |       t        j                  | |      S || j                  u rt	        |      |S )a  Remove and return value for item identified by `key`.

        If the `key` is not found then return `default` if given. If `default`
        is not given then raise :exc:`KeyError`.

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

        >>> sd = SortedDict({'a': 1, 'b': 2, 'c': 3})
        >>> sd.pop('c')
        3
        >>> sd.pop('z', 26)
        26
        >>> sd.pop('y')
        Traceback (most recent call last):
          ...
        KeyError: 'y'

        :param key: `key` for item
        :param default: `default` value if key not found (optional)
        :return: value for item
        :raises KeyError: if `key` not found and `default` not given

        )r    rB   r   _SortedDict__not_givenKeyErrorr/   r   defaults      r2   r   zSortedDict.pop  sG    0 $;c"88D#&&$***sm#Nr4   c                 r    | st        d      | j                  |      }t        j                  | |      }||fS )a_  Remove and return ``(key, value)`` pair at `index` from sorted dict.

        Optional argument `index` defaults to -1, the last item in the sorted
        dict. Specify ``index=0`` for the first item in the sorted dict.

        If the sorted dict is empty, raises :exc:`KeyError`.

        If the `index` is out of range, raises :exc:`IndexError`.

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

        >>> sd = SortedDict({'a': 1, 'b': 2, 'c': 3})
        >>> sd.popitem()
        ('c', 3)
        >>> sd.popitem(0)
        ('a', 1)
        >>> sd.popitem(100)
        Traceback (most recent call last):
          ...
        IndexError: list index out of range

        :param int index: `index` of item (default -1)
        :return: key and value pair
        :raises KeyError: if sorted dict is empty
        :raises IndexError: if `index` out of range

        zpopitem(): dictionary is empty)r   r   rB   r   )r/   r&   r   rI   s       r2   popitemzSortedDict.popitem  s;    8 ;<<nnU#s#U|r4   c                 .    | j                   |   }|| |   fS )a0  Return ``(key, value)`` pair at `index` in sorted dict.

        Optional argument `index` defaults to -1, the last item in the sorted
        dict. Specify ``index=0`` for the first item in the sorted dict.

        Unlike :func:`SortedDict.popitem`, the sorted dict is not modified.

        If the `index` is out of range, raises :exc:`IndexError`.

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

        >>> sd = SortedDict({'a': 1, 'b': 2, 'c': 3})
        >>> sd.peekitem()
        ('c', 3)
        >>> sd.peekitem(0)
        ('a', 1)
        >>> sd.peekitem(100)
        Traceback (most recent call last):
          ...
        IndexError: list index out of range

        :param int index: index of item (default -1)
        :return: key and value pair
        :raises IndexError: if `index` out of range

        )r   )r/   r&   r   s      r2   peekitemzSortedDict.peekitem  s     6 jjDI~r4   c                 h    || v r| |   S t         j                  | ||       | j                  |       |S )a  Return value for item identified by `key` in sorted dict.

        If `key` is in the sorted dict then return its value. If `key` is not
        in the sorted dict then insert `key` with value `default` and return
        `default`.

        Optional argument `default` defaults to none.

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

        >>> sd = SortedDict()
        >>> sd.setdefault('a', 1)
        1
        >>> sd.setdefault('a', 10)
        1
        >>> sd
        SortedDict({'a': 1})

        :param key: key for item
        :param default: value for item (default None)
        :return: value for item identified by `key`

        )rB   rH   r   r   s      r2   
setdefaultzSortedDict.setdefault  s8    0 $;9sG,sr4   c                    | s>t        j                  | g|i | | j                  t         j                  |              y|s't	        |      dk(  rt        |d   t               r|d   }nt        |i |}dt	        |      z  t	        |       kD  rKt         j                  | |       | j                          | j                  t         j                  |              y|D ]  }| j                  |||           y)as  Update sorted dict with items from `args` and `kwargs`.

        Overwrites existing items.

        Optional arguments `args` and `kwargs` may be a mapping, an iterable of
        pairs or keyword arguments. See :func:`SortedDict.__init__` for
        details.

        :param args: mapping or iterable of pairs
        :param kwargs: keyword arguments mapping

        Nr   r   
   )rB   r!   r"   r   lenrM   r   _setitem)r/   r0   r1   pairsr   s        r2   r!   zSortedDict.update!  s     KK.t.v.dmmD12#d)q.ZQ-FGE$)&)EUOs4y(KKe$dmmD12 /c5:./r4   c                 ^    t         j                  |       }t        |       | j                  |ffS )zSupport for pickle.

        The tricks played with caching references in
        :func:`SortedDict.__init__` confuse pickle so customize the reducer.

        )rB   rY   typer   )r/   rO   s     r2   
__reduce__zSortedDict.__reduce__C  s)     		$T
TYY.//r4   c                       j                   }t               j                  }|dndj                  |      }dj                  dj	                   fd j
                  D              }dj                  |||      S )zReturn string representation of sorted dict.

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

        :return: string representation

         z{0!r}, z{0!r}: {1!r}z, c              3   6   K   | ]  } ||           y wrK   r\   )r]   r   item_formatr/   s     r2   r^   z&SortedDict.__repr__.<locals>.<genexpr>[  s     L#+c495Ls   z{0}({1}{{{2}}}))r   r   rq   rp   joinr   )r/   r   	type_namekey_argrO   r   s   `    @r2   r~   zSortedDict.__repr__N  sk     yyJ''	")*:*:4*@$++		LLL ''	7EBBr4   c                       j                   }|j                          t               t        |      k(  sJ t         fd|D              sJ y)zNCheck invariants of sorted dict.

        Runtime complexity: `O(n)`

        c              3   &   K   | ]  }|v  
 y wrK   r\   )r]   r   r/   s     r2   r^   z$SortedDict._check.<locals>.<genexpr>h  s     033$;0r_   N)r   _checkr   all)r/   r   s   ` r2   r   zSortedDict._check_  s>     

4yCJ&&0%0000r4   rK   )).rq   r   r   rr   r3   rs   r   r@   r   rD   r   r   rH   r   rS   rU   rW   rY   __copy__classmethodrb   rd   rO   ri   sys
hexversion&_SortedDict__make_raise_attributeerrorru   rv   rw   rx   ry   rz   objectr   r   r   r   r   r   r!   r.   r   r   r~   r   r\   r4   r2   r   r   +   sP   DJI&X    *0	!	%+, H00
7 H 5 5$%& ~~
"	$ 0WE	.z6B0xH
/WE	.z6B0xH
!F !
 +K* B!H>>/> G0 C C 	1r4   r   c                     | j                   }|j                  }t        j                  }t	        |t
              r||   }||= |D ]  } |||        y|j                  |      } |||       y)a
  Remove item at `index` from sorted dict.

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

    Supports slicing.

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

    >>> sd = SortedDict({'a': 1, 'b': 2, 'c': 3})
    >>> view = sd.keys()
    >>> del view[0]
    >>> sd
    SortedDict({'b': 2, 'c': 3})
    >>> del view[-1]
    >>> sd
    SortedDict({'b': 2})
    >>> del view[:]
    >>> sd
    SortedDict({})

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

    N)_mappingr   rB   rD   rM   slicer   )r/   r&   r   r   dict_delitemrd   r   s          r2   _view_delitemr   k  sn    2 }}HNNE##L%U|%L 	(C3'	( iiXs#r4   c                   .    e Zd ZdZdZed        Zd ZeZ	y)r?   zSorted keys view is a dynamic view of the sorted dict's keys.

    When the sorted dict's keys change, the view reflects those changes.

    The keys view implements the set and sequence abstract base classes.

    r\   c                     t        |      S rK   r   r`   its     r2   _from_iterablezSortedKeysView._from_iterable      }r4   c                 4    | j                   j                  |   S )a  Lookup key at `index` in sorted keys views.

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

        Supports slicing.

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

        >>> sd = SortedDict({'a': 1, 'b': 2, 'c': 3})
        >>> skv = sd.keys()
        >>> skv[0]
        'a'
        >>> skv[-1]
        'c'
        >>> skv[:]
        ['a', 'b', 'c']
        >>> skv[100]
        Traceback (most recent call last):
          ...
        IndexError: list index out of range

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

        )r   r   )r/   r&   s     r2   __getitem__zSortedKeysView.__getitem__  s    6 }}""5))r4   N
rq   r   r   rr   	__slots__r   r   r   r   rD   r\   r4   r2   r?   r?     s.     I  *<  Kr4   r?   c                   .    e Zd ZdZdZed        Zd ZeZ	y)rf   zSorted items view is a dynamic view of the sorted dict's items.

    When the sorted dict's items change, the view reflects those changes.

    The items view implements the set and sequence abstract base classes.

    r\   c                     t        |      S rK   r   r   s     r2   r   zSortedItemsView._from_iterable  r   r4   c                     | j                   }|j                  }t        |t              r||   }|D cg c]	  }|||   f c}S ||   }|||   fS c c}w )a  Lookup item at `index` in sorted items view.

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

        Supports slicing.

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

        >>> sd = SortedDict({'a': 1, 'b': 2, 'c': 3})
        >>> siv = sd.items()
        >>> siv[0]
        ('a', 1)
        >>> siv[-1]
        ('c', 3)
        >>> siv[:]
        [('a', 1), ('b', 2), ('c', 3)]
        >>> siv[100]
        Traceback (most recent call last):
          ...
        IndexError: list index out of range

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

        r   r   rM   r   r/   r&   r   _mapping_listrd   r   s         r2   r   zSortedItemsView.__getitem__  sb    6 == eU# 'D489SS(3-(99E"HSM!! :s   ANr   r\   r4   r2   rf   rf     s/     I  #"L  Kr4   rf   c                       e Zd ZdZdZd ZeZy)rh   zSorted values view is a dynamic view of the sorted dict's values.

    When the sorted dict's values change, the view reflects those changes.

    The values view implements the sequence abstract base class.

    r\   c                     | j                   }|j                  }t        |t              r||   }|D cg c]  }||   	 c}S ||   }||   S c c}w )a  Lookup value at `index` in sorted values view.

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

        Supports slicing.

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

        >>> sd = SortedDict({'a': 1, 'b': 2, 'c': 3})
        >>> svv = sd.values()
        >>> svv[0]
        1
        >>> svv[-1]
        3
        >>> svv[:]
        [1, 2, 3]
        >>> svv[100]
        Traceback (most recent call last):
          ...
        IndexError: list index out of range

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

        r   r   s         r2   r   zSortedValuesView.__getitem__  sX    6 == eU# 'D-12cHSM22E"} 3s   AN)rq   r   r   rr   r   r   r   rD   r\   r4   r2   rh   rh     s     I#L  Kr4   rh   )rr   r   r<   	itertoolsr   
sortedlistr   r   	sortedsetr   collections.abcr	   r
   r   r   r   ImportErrorcollectionsrB   r   r   r?   rf   rh   r\   r4   r2   <module>r      s   $    2  O }1 }1@#$L. Xx . b6 i 6 r1 z8 1 q  ONNOs   A! !A76A7