o
    i4j                  
   @   s  d Z ddlZddlZddlZddlZddlZddlmZ ddl	m
Z ddlmZ ddlmZ ddl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 dd
lmZmZmZm Z  ej!dkZ"ej#j$Z%e&ede% Z'e&ede% Z(ej#j)Z*ej#j+Z,e(ej#j-Z.ej/j0dkrdndZ1dZ2e2Z3ej4j5Z6ej#j7Z8ej#j9Z:dd Z;ee;dd Z<ee=dd Z>edd Z?ee(e(ej@ejAejAe(ejAdddd ZBedd ZCed d! ZDee(e(e(e(e(e(ejEejEd"dd#d$ ZFeejGd%eejHd%d&d' ZIeejJd%d(d) ZKeejLd%d*d+ ZMe(j0d, d-kr/e(d.ZNe(d/ZOe(d0ZPed1ejQidd2d3 ZRne(d4ZNe(d5ZOe(d6ZPed1ejQidd7d3 ZRee(e(e(e(e(d8dd9d: ZSeejTd%d;d< ZUdd=lmVZVmWZWmXZXmYZYmZZZm[Z[ G d>d? d?eZZ\G d@dA dAeZZ]G dBdC dCeZZ^G dDdE dEeZZ_G dFdG dGe[Z`edHdIdJgZadKdL Zbeb Zce:dMv re:dNkrdOZdeeed eejQejQdPddQdR ZfeejQejQejQejQejQejQdSddTdU ZgeejQejQejQejQdVddWdX ZheejQejQejQejQdVddYdZ Zid[d\ Zjejd]Zkejd^Zle:d]kreknelZmnd_e: Zdeneded`da Zodbdc Zpeepddde Zqedfe(iddgdh Zreejsd%didj ZtdS )kz&
Hash implementations for Numba types
    N)
namedtuple)ir)literal_unroll)overloadoverload_method	intrinsicregister_jitable)errors)typesutils)	grab_bytegrab_uint64_t)	const_intget_next_intget_next_int32get_state_ptr)   
   zint%szuint%s       =   iCB c                 C   s   d S N )	hash_funcr   r   d/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/numba/cpython/hashing.py_defer_hash1   s   r   c                    s   d|  d  fdd}|S )Nzunhashable type: ''c                    s   |d u rt  | S r   )	TypeError)objr   err_msgr   r   impl9   s   zol_defer_hash.<locals>.implr   )r   r   r!   r   r   r   ol_defer_hash5   s   r"   c                    s   d|  d  fdd}|S )Nz+No __hash__ is defined for object of type 'zn' and a generic hash() cannot be performed as there is no suitable object represention in Numba compiled code!c                    s"   t | drt| t| dS t )N__hash__)hasattrr   getattrr   )r   Zattempt_generic_msgr   r   r!   I   s   
zhash_overload.<locals>.implr   )r   r!   r   r&   r   hash_overloadB   s
   r'   c                 C   s    t | }|tdkrtd}|S )N)
_Py_hash_tint)valZasintr   r   r   process_returnQ   s   r-   )xymesign_PyHASH_MODULUS_PyHASH_BITSlocalsc                 C   s
  t | st | r| dkrtS t S trt }t|S tS t	| \}}d}|dk r0d}| }d}|r^|d> t
@ |td ? B }|d9 }|d8 }t|}||8 }||7 }|t
kr\|t
8 }|s4|dkrg|t }n
td d| t  }||> t
@ |t| ? B }|| }t|S )Nr      r(      g      A)npisfiniteisinf_PyHASH_INF_py310_or_later_prng_random_hashr-   _PyHASH_NANmathfrexpr3   r4   r+   )vr.   r0   r1   r2   r/   r   r   r   _Py_HashDouble`   s>   



rC   c                 C   s   dd }t t j}||fS )Nc                 S   s   |d }| |t S )Nr   )Zfpextr   Z
DoubleType)cgctxbuilder	signatureargsr,   r   r   r   r!      s   z_fpext.<locals>.impl)r
   float64Zfloat32)tyctxr,   r!   sigr   r   r   _fpext   s   rK   c                 C   s   dd }t  }||fS )Nc                 S   s@   t | |d}tt}tdkrt| ||}|S t| |||d}|S )NZinternalr   F)r   r   _hash_widthr   r   )rD   rE   rF   rG   Z	state_ptrbitsvaluer   r   r   r!      s   	z_prng_random_hash.<locals>.impl)r*   )rI   r!   rJ   r   r   r   r>      s   r>   )r.   p1p2p3p4r3   r4   _PyLong_SHIFTc           
      C   s   dt  }td |? }dt  d }d}tt  }t|d ddD ]'}|t > }|t@ }||? }	||	B }|t| |t  ? |@ 7 }|tkrG|t8 }q t|S )Nr   r   @   r7   r(   )rS   r
   Zuint32r4   ranger3   r*   )
r,   Z
_tmp_shiftZ
mask_shiftir.   rQ   idxrO   rP   rR   r   r   r   
_long_impl   s   rX   r#   c                    sH   t jdkrdndtdt| ddrtjntj  fdd}|S )	Nl        r)   l         signedFc                    s    | } t | }|tk r*| dkrd}t|S | kr"t}t|S t| }t|S d}| dk r5|  } d}t| }|r>| }t|S )Nr   FT)absr3   r*   rX   r-   )r,   magretZneeds_negateZ_BIGZ_HASH_I64_MINZ_SIGNED_MINr   r   r!      s&   
	zint_hash.<locals>.impl)sysmaxsizer
   Zint64r%   uint64r,   r!   r   r^   r   int_hash   s
   
rc   c                 C   s"   | j dkrdd }|S dd }|S )NrT   c                 S   s   t | }|S r   )rC   )r,   hashedr   r   r   r!     s   zfloat_hash.<locals>.implc                 S   s   t t| }t|}|S r   )r9   rH   rK   rC   )r,   Z
fpextendedrd   r   r   r   r!     s   )bitwidthrb   r   r   r   
float_hash  s
   
	rf   c                 C      dd }|S )Nc                 S   s(   t | j}t | j}|t|  }t|S r   )hashrealimag_PyHASH_IMAGr-   )r,   ZhashrealZhashimagcombinedr   r   r   r!   (  s   

zcomplex_hash.<locals>.implr   rb   r   r   r   complex_hash&  s   
rm         l   Jfq	 l   OkO8 l   g,,> r.   c                 C      | t d> | t d? B S )Nr   !   r
   ra   r.   r   r   r   _PyHASH_XXROTATE@     rt   l   yn< l   wJ igVc                 C   rp   )N      rr   rs   r   r   r   rt   I  ru   )acclane_PyHASH_XXPRIME_5_PyHASH_XXPRIME_1tlc                 C   s   t | }t}t| D ]}t|}|tdkr dS ||t 7 }t|}|t9 }q
||ttdA A 7 }|tdkr<tdS t|S )Nr(   is5 iK*\)	lenrz   r   rh   _Py_uhash_t_PyHASH_XXPRIME_2rt   r{   r-   )tupr|   rx   r.   ry   r   r   r   _tuple_hashO  s   
r   c                 C   rg   )Nc                 S      t | S r   )r   )r,   r   r   r   r!   h     ztuple_hash.<locals>.implr   rb   r   r   r   
tuple_hashf     r   )c_size_tc_ubytec_uint64	pythonapi	StructureUnionc                   @      e Zd ZdefdefgZdS )FNVprefixsuffixN)__name__
__module____qualname__r   _fields_r   r   r   r   r         r   c                   @   r   )SIPHASHk0k1N)r   r   r   r   r   r   r   r   r   r     r   r   c                   @       e Zd Zded fdefgZdS )DJBX33Apadding   r   Nr   r   r   r   r   r   r   r   r   r   r         
r   c                   @   r   )EXPATr   r   ZhashsaltNr   r   r   r   r   r     r   r   c                   @   s2   e Zd Zded fdefdefdefdefgZdS )_Py_HashSecret_tZuc   fnvsiphashdjbx33aexpatN)	r   r   r   r   r   r   r   r   r   r   r   r   r   r     s    
r   _hashsecret_entrysymbolrN   c                     sJ   t td} i   fdd}|d| jj |d| jj |d| jj  S )zRead hash secret from the Python process

    Returns
    -------
    info : dict
        - keys are "djbx33a_suffix", "siphash_k0", siphash_k1".
        - values are the namedtuple[symbol:str, value:int]
    Z_Py_HashSecretc                    s>   d | }t|}t|}t|| t||d | < d S )Nz_numba_hashsecret_{})r   rN   )formatctypesr   Z	addressofllZ
add_symbolr   )namer,   Zsymbol_nameaddrinfor   r   inject  s
   


z!_build_hashsecret.<locals>.injectdjbx33a_suffix
siphash_k0
siphash_k1)r   Zin_dllr   r   r   r   r   r   )Zpyhashsecretr   r   r   r   _build_hashsecret  s   r   )	siphash13	siphash24r   r   a  FNV hashing is not implemented in Numba. See PEP 456 https://www.python.org/dev/peps/pep-0456/ for rationale over not using FNV. Numba will continue to work, but hashes for built in types will be computed using siphash24. This will permit e.g. dictionaries to continue to behave as expected, however anything relying on the value of the hash opposed to hash as a derived property is likely to not work as expected.r.   bc                 C   s    t | |> | t d| ? B S )NrT   rr   r   r   r   r   _ROTATE  s    r   ar   cdstc                 C   sB   | |7 } ||7 }t ||| A }t |||A }t | d} | |||fS )Nr   )r   r   r   r   r   _HALF_ROUND  s   
r   v0v1v2v3c                 C   s@   t | |||dd\} }}}t ||| |dd\}}} }| |||fS )Nrv   r         )r   r   r   r   r   _SINGLE_ROUND$  s   r   c                 C   s8   t | |||\} }}}t | |||\} }}}| |||fS r   )r   r   r   r   r   _DOUBLE_ROUND-  s   r   c                    sr   | dkr	t d n| dkrtd nJ dttjtjtjtjtjtjtjtjtjtjd
d fd	d
}|S )Nr   Tr   Fr   Zunreachable)
r   r   r   r   r   mir   maskjmpohexefefr5   c                    s   t |d> }| t dA }|t dA }| t dA }|t dA }d}	|dkrMt||	}
|	d7 }	|d8 }||
N }||||\}}}}||
N }|dks)t d}|	d }t d	}|d
kryd}t ||>  }||@ t t||d |> B }|dkrd}t ||>  }||@ t t||d |> B }|dkrd}t ||>  }||@ t t||d |> B }|dkr|t dM }tdD ]}|d }t ||>  }||@ t t||| |> B }q|dkrd}t ||>  }||@ t t||d |> B }|dkr!d}t ||>  }||@ t t||d |> B }|dkr7| }||@ t t||d B }||O }||N }||||\}}}}||N }||N }||||\}}}}||||\}}}} rv||||\}}}}||A ||A A }|S )N8   l   ue`5{ l   mo\I{# l   ar\c l   ser+# r   rn   r7         0      (      r   ro   l        r   r      )r
   ra   r   r   rU   )r   r   srcZsrc_szr   r   r   r   r   rW   r   r   Zboffsetr   r   r   rV   Z_EXTRA_ROUNDZ_ROUNDERr   r   _siphash@  s   






z_gen_siphash.<locals>._siphash)r   r   r   r
   ra   )algr   r   r   r   _gen_siphash6  s(   
Er   r   r   z'Unsupported hashing algorithm in use %sc                    sD   t |tjstdt|j j tj}||} fdd}||fS )z&Emit code to load the hashsecret.
    zrequires literal stringc                    sL   |j }z| }W n ty   tj|td d}Y nw ||}|S )NrT   r   )moduleZ
get_globalKeyErrorr   ZGlobalVariableZIntTypeload)rD   rE   rJ   rG   modgvrB   symr   r   r!     s   
z%_inject_hashsecret_read.<locals>.impl)	
isinstancer
   ZStringLiteralr	   ZTypingError_hashsecretZliteral_valuer   ra   )rI   r   ZrestyrJ   r!   r   r   r   _inject_hashsecret_read  s   
r   c                 C   s
   t |  jS r   )r   rN   r   r   r   r   _load_hashsecret  s   
r   c                 C   rg   )Nc                 S   r   r   )r   r   r   r   r   imp  r   z"_impl_load_hashsecret.<locals>.impr   )r   r   r   r   r   _impl_load_hashsecret  r   r   _hashc                 C   s   |dkrt dS |tk r3td}t|D ]}|d> | tt| | }q||N }|tdN }t |S tt	
tdt	
td| |}t |}t |S )Nr   i  r   r   r   r   )r-   _Py_HASH_CUTOFFr~   rU   r9   Zuint8r   r   
_siphasherr
   ra   )r,   _lenr   rW   tmpr   r   r   _Py_HashBytes  s   r   c                    s   ddl m   fdd}|S )Nr   _kind_to_byte_widthc                    s4    | j }t| }| j}|dkr|S t| j|| S )Nr(   )_kindr}   r   r   _data)r,   Z	kindwidthr   Zcurrent_hashr   r   r   r!     s   
zunicode_hash.<locals>.impl)Znumba.cpython.unicoder   rb   r   r   r   unicode_hash  s   r   )u__doc__r@   numpyr9   r_   r   warningscollectionsr   Zllvmlite.bindingZbindingr   Zllvmliter   Znumbar   Znumba.core.extendingr   r   r   r   Z
numba.corer	   r
   r   Znumba.core.unsafe.bytesr   r   Znumba.cpython.randomimplr   r   r   r   Z	PYVERSIONr=   	hash_infowidthrL   r%   r*   r~   infr<   nanr?   modulusr3   Zintpre   r4   Z_PyHASH_MULTIPLIERrk   int_infobits_per_digitrS   cutoffr   	algorithmZ_Py_hashfunc_namer   r"   rh   r'   r-   doubleZintcrC   rK   r>   Zint32rX   IntegerBooleanrc   Floatrf   Complexrm   r{   r   rz   ra   rt   r   Z	BaseTupler   r   r   r   r   r   r   r   r   r   r   r   r   r   r   msgwarnr   r   r   r   r   Z
_siphash13Z
_siphash24r   
ValueErrorr   r   r   r   ZUnicodeTyper   r   r   r   r   <module>   s   




1





,






 



/



[




