Ë
    7^(h  ã                   ó(   — d dl mZ d„ Zd„ Zd„ Zd„ Zy)é    )ÚOrderedDictc                 óî   — | sdgS t        | d   t        «      s%t        | dd «      }|D �cg c]  }| d   f|z   ‘Œ c}S t        | dd «      }|D ��cg c]  }| d   D ]  }|f|z   ‘Œ
 Œ c}}S c c}w c c}}w )z¨
    >>> from sympy.multipledispatch.utils import expand_tuples
    >>> expand_tuples([1, (2, 3)])
    [(1, 2), (1, 3)]

    >>> expand_tuples([1, 2])
    [(1, 2)]
    © r   é   N)Ú
isinstanceÚtupleÚexpand_tuples)ÚLÚrestÚtÚitems       úZ/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/multipledispatch/utils.pyr	   r	      sˆ   € ñ ØˆtˆÜ˜˜!™œeÔ$Ü˜Q˜q˜r˜UÓ#ˆØ%)Ö* ��1‘�˜!“Ò*Ð*ä˜Q˜q˜r˜UÓ#ˆØ%)×; °a¸±dÒ;¨d��˜!“Ð;�Ó;Ð;ùò +ùó <s   «A,ÁA1c                 óÒ  ‡— t        | «      Š‰j                  «       D ��ci c]  \  }}|t        |«      “Œ c}}Št        j                  ˆfd„| D «       «      }g }|rf|j                  «       \  }}|j                  |«       | j                  |d«      D ]*  }|‰|   v sJ ‚‰|   j                  |«       ‰|   rŒ&d||<   Œ, |rŒft        ˆfd„| D «       «      rt        d«      ‚|S c c}}w )a2   Topological sort algorithm by Kahn [1] - O(nodes + vertices)

    inputs:
        edges - a dict of the form {a: {b, c}} where b and c depend on a
    outputs:
        L - an ordered list of nodes that satisfy the dependencies of edges

    >>> from sympy.multipledispatch.utils import _toposort
    >>> _toposort({1: (2, 3), 2: (3, )})
    [1, 2, 3]

    Closely follows the wikipedia page [2]

    [1] Kahn, Arthur B. (1962), "Topological sorting of large networks",
    Communications of the ACM
    [2] https://en.wikipedia.org/wiki/Toposort#Algorithms
    c              3   ó,   •K  — | ]  }|‰vsŒ|–— Œ y ­w©Nr   ©Ú.0ÚvÚincoming_edgess     €r   ú	<genexpr>z_toposort.<locals>.<genexpr>-   s   øè ø€ ÒI 1°¸.Ò1HœQÑIùs   ƒ	�r   Nc              3   óB   •K  — | ]  }‰j                  |d «      –— Œ y ­wr   ©Úgetr   s     €r   r   z_toposort.<locals>.<genexpr>8   s   øè ø€ Ò
6¨1ˆ>×Ñ˜a ×&Ñ
6ùs   ƒzInput has cycles)Úreverse_dictÚitemsÚsetr   ÚfromkeysÚpopitemÚappendr   ÚremoveÚanyÚ
ValueError)	ÚedgesÚkÚvalÚSr
   ÚnÚ_Úmr   s	           @r   Ú	_toposortr*      sé   ø€ ô$ " %Ó(€NØ0>×0DÑ0DÓ0F×G¡f a¨�aœ˜S›‘kÓG€NÜ×ÑÓI¨ÔIÓI€AØ
€Aá
Ø�y‰y‹{‰ˆˆ1Ø	�‰�ŒØ—‘˜1˜bÓ!ò 	ˆAØ˜ qÑ)Ñ)Ð)Ð)Ø˜1Ñ×$Ñ$ QÔ'Ø! !Ó$Ø��!’ð		ò ô Ó
6°Ô
6Ô6ÜÐ+Ó,Ð,Ø€Hùó Hs    C#c                 ó^   — i }| D ]%  }| |   D ]  }|j                  |d«      |fz   ||<   Œ Œ' |S )a›  Reverses direction of dependence dict

    >>> d = {'a': (1, 2), 'b': (2, 3), 'c':()}
    >>> reverse_dict(d)  # doctest: +SKIP
    {1: ('a',), 2: ('a', 'b'), 3: ('b',)}

    :note: dict order are not deterministic. As we iterate on the
        input dict, it make the output of this function depend on the
        dict order. So this function output order should be considered
        as undeterministic.

    r   r   )ÚdÚresultÚkeyr%   s       r   r   r   =   sM   € ð €FØò 8ˆØ�S‘6ò 	8ˆCØ Ÿ*™* S¨"Ó-°°Ñ7ˆF�3ŠKñ	8ð8ð €Mó    c                 ób   — i }|D ]'  } | |«      }||vrg ||<   ||   j                  |«       Œ) |S )aÛ   Group a collection by a key function

    >>> from sympy.multipledispatch.utils import groupby
    >>> names = ['Alice', 'Bob', 'Charlie', 'Dan', 'Edith', 'Frank']
    >>> groupby(len, names)  # doctest: +SKIP
    {3: ['Bob', 'Dan'], 5: ['Alice', 'Edith', 'Frank'], 7: ['Charlie']}

    >>> iseven = lambda x: x % 2 == 0
    >>> groupby(iseven, [1, 2, 3, 4, 5, 6, 7, 8])  # doctest: +SKIP
    {False: [1, 3, 5, 7], True: [2, 4, 6, 8]}

    See Also:
        ``countby``
    )r   )ÚfuncÚseqr,   r   r.   s        r   Úgroupbyr3   S   sH   € ð  	€AØò ˆÙ�4‹jˆØ�a‰<ØˆAˆc‰FØ	ˆ#‰�‰�dÕð	ð
 €Hr/   N)Úcollectionsr   r	   r*   r   r3   r   r/   r   ú<module>r5      s   ðÝ #ò<ò*!òHó,r/   