o
    i                     @   s  d 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
mZmZ ddlmZmZmZmZmZmZmZmZmZ ddlmZ ddlmZ dd	lmZmZ dd
lmZm Z m!Z! dd Z"dd Z#dZ$dZ%dZ&dZ'dZ(dZ)dd Z*e!dd Z+dd Z,dd Z-dd Z.dd  Z/e0d!d"Z1G d#d$ d$e2Z3G d%d& d&e2Z4G d'd( d(e2Z5d)d* Z6ee7d+d, Z8ee7e
j9d-d. Z:ee;e
j<d/d0 Z=eej>e
j<e
j?d1d2 Z@ed3e
j<d4d5 ZAed6e
jBeejCd7d8 ZDed9e
j<e
j?d:d; ZEe!d<d= ZFe e
j<d>d?d@ ZGe!dAdB ZHe e
j<dCdDdE ZIe!dFdG ZJe e
j<dHdIdJ ZKe!dKdL ZLe e
j<dMdNdO ZMe!dPdQ ZNe e
j<dRdSdT ZOdUdV ZPe!dWdX ZQe e
j<dYdZd[ ZRd\d] ZSe!d^d_ ZTe e
j<d`dadb ZUdcdd ZVe!dedf ZWe e
j<dgdhdi ZXedje
j<e
j9dkdl ZYdmdn ZZej[eSfej\eYfej]ePfej^eVffD ]
\Z_Z`eZe_e` qeejae e
j<dodpdq Zbeejce e
j<drdsdt Zdeejee e
j<dudvdw Zfeejge e
j<dxdydz Zhe!d{d| Zie e
j<d}d~d Zje!dd Zkeejle e
j<ddd Zmeejne e
j<ddd Zoe!dd Zpeejqdd Zreejsdd Zte!dd Zueejvdd Zweejxdd Zyeejze
j<e
j<dd Z{ee
j<e
j<dd Z|dS )z&
Support for native homogeneous sets.
    N)cached_property)ir)typestypingcgutils)	lower_builtin
lower_castiternext_implimpl_ret_borrowedimpl_ret_new_refimpl_ret_untrackedfor_itercall_lenRefType)	quicksort)slicing)NumbaValueErrorTypingError)overloadoverload_method	intrinsicc                 C   s4   t |}| | }|||}| j|||dS )zx
    Given a set value and type, get its payload structure (as a
    reference, so that mutations are seen by all).
    ref)r   
SetPayloadget_data_typeZ
as_pointerbitcastmake_data_helper)contextbuilderset_typeptrpayload_typeZptrtypayload r#   c/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/numba/cpython/setobj.pyget_payload_struct   s   
r%   c                 C   s   |  t|}| |S )z7
    Return the entry size for the given set type.
    )r   r   SetEntryget_abi_sizeof)r   r   Zlltyr#   r#   r$   get_entry_size#   s   
r(   i      Fc                 C   s`   | j }|t}|||fi }| ||}|||f}t| ||}	t|jt	}
|
|	||
S )z.
    Compute the hash of the given value.
    )typing_contextresolve_value_typehashget_call_typeget_functionis_hash_usedr   ConstanttypeFALLBACKselect)r   r   typvalue	typingctxfntysigfnhZis_okfallbackr#   r#   r$   get_hash_value;   s   
r?   c                    s.    fdd}|  t}||  fi }||fS )Nc                    s   t | | |d S Nr   )r?   )r   r   r7   argsr8   r#   r$   implL   s   z'_get_hash_value_intrinsic.<locals>.impl)r.   r/   r0   )r9   r8   rC   r:   r;   r#   rB   r$   _get_hash_value_intrinsicJ   s   
rD   c                 C      t |jt}|d||S )z8
    Whether the hash value denotes an empty entry.
    ==)r   r3   r4   EMPTYicmp_unsigned)r   r   r=   emptyr#   r#   r$   is_hash_emptyS      rJ   c                 C   rE   )z9
    Whether the hash value denotes a deleted entry.
    rF   r   r3   r4   DELETEDrH   r   r   r=   Zdeletedr#   r#   r$   is_hash_deletedZ   rK   rO   c                 C   rE   )z9
    Whether the hash value denotes an active entry.
    <rL   rN   r#   r#   r$   r2   a   s   r2   c                     sH   t dd  D std  t  fdd D s"td  d S )Nc                 S   s   g | ]}t |tjqS r#   )
isinstancer   Set).0r7   r#   r#   r$   
<listcomp>k   s    z!check_all_set.<locals>.<listcomp>z All arguments must be Sets, got c                    s   g | ]
} d  j |j kqS )r   dtype)rS   srA   r#   r$   rT   n   s    z'All Sets must be of the same type, got )allr   rX   r#   rX   r$   check_all_setj   s
   rZ   SetLoopindexentrydo_breakc                   @   s   e Zd Zdd Zedd Zejdd Zedd Zejdd Zed	d
 Zejdd
 Zedd Z	e	jdd Z	edd Z
e
jdd Z
edd Zedd Zdd Zd ddZejd!ddZejdd ZdS )"_SetPayloadc                 C   s<   t ||||}|| _|| _|| _|| _|d| _|| _d S )Nentries)r%   _context_builder_ty_payloadZ_get_ptr_by_name_entries_ptr)selfr   r   r   r    r"   r#   r#   r$   __init__w   s   
z_SetPayload.__init__c                 C      | j jS Nre   maskrh   r#   r#   r$   rm         z_SetPayload.maskc                 C      || j _d S rk   rl   rh   r8   r#   r#   r$   rm      s   c                 C   rj   rk   re   usedrn   r#   r#   r$   rs      ro   z_SetPayload.usedc                 C   rp   rk   rr   rq   r#   r#   r$   rs         c                 C   rj   rk   re   fillrn   r#   r#   r$   rv      ro   z_SetPayload.fillc                 C   rp   rk   ru   rq   r#   r#   r$   rv      rt   c                 C   rj   rk   re   fingerrn   r#   r#   r$   rx      ro   z_SetPayload.fingerc                 C   rp   rk   rw   rq   r#   r#   r$   rx      rt   c                 C   rj   rk   re   dirtyrn   r#   r#   r$   rz      ro   z_SetPayload.dirtyc                 C   rp   rk   ry   rq   r#   r#   r$   rz      rt   c                 C      | j S )z>
        A pointer to the start of the entries array.
        )rf   rn   r#   r#   r$   ra         z_SetPayload.entriesc                 C   r{   )zC
        A pointer to the start of the NRT-allocated area.
        )rg   rn   r#   r#   r$   r       r|   z_SetPayload.ptrc                 C   s2   t | j| j|}| jj| jt| j|d}|S )z)
        Get entry number *idx*.
        r   )	r   geprc   rf   rb   r   r   r&   rd   )rh   idxZ	entry_ptrr^   r#   r#   r$   	get_entry   s   

z_SetPayload.get_entryFc                    s  
j 
jj}
j}
jj}j}|tj	}|
|||fi }	||	t|d}
t|d}t}t|}rQ|dtd}d dd} 	
fdd	}tt|t# |}|| ||
}||}|| W d
   n1 sw   Y  | |A |}|| |}||}|
||}|||}|| || | W d
   n1 sw   Y  , r"|}}d|||}|| | W d
   n	1 s2w   Y    | W d
   n	1 sMw   Y  | tdd}| tj!  | tj" ||fS )ag  
        Lookup the *item* with the given hash values in the entries.

        Return a (found, entry index) tuple:
        - If found is true, <entry index> points to the entry containing
          the item.
        - If found is false, <entry index> points to the empty entry that
          the item can be written to (only if *for_insert* is true)
              r)   zlookup.bodyzlookup.foundzlookup.not_foundz
lookup.endc              	      s2  
 | }|j}d|* 	|jf}|   W d   n1 s0w   Y  W d   n1 s?w   Y  t|  W d   n1 s]w   Y  rt|  }	d|| |}
| W d   dS 1 sw   Y  dS dS )zO
            Check entry *i* against the value being searched for.
            rF   N)r   r/   if_thenrH   keybranchrJ   rO   loadr6   store)ir^   Z
entry_hasheqjZbb_foundZbb_not_foundr   r   Zeqfn
for_insertZ
free_indexZfree_index_sentinelr=   itemrh   r#   r$   check_entry   s*   

"z(_SetPayload._lookup.<locals>.check_entryNrF   found)#rb   rc   r4   rm   rd   rV   r-   r.   operatorr   r0   r1   r   r3   r   alloca_once_valueand_append_basic_block	for_rangeLINEAR_PROBESr   addr   r   
goto_blocklshrmulr6   rH   position_at_endphiZIntTypeZadd_incomingtrue_bit	false_bit)rh   r   r=   r   intp_trm   rV   Ztyctxr:   r;   onefiveZperturbr]   bb_bodybb_endr   r   pr   r   r#   r   r$   _lookup   sx   






 







z_SetPayload._lookupNc              	   c   s    | j }| j}|tj}t|d}|| j|}t	j
|||d?}| |j}t|||j}	||	 t|j||jd}
|
V  W d   n1 sLw   Y  W d   dS W d   dS 1 sdw   Y  dS )zG
        Iterate over the payload's entries.  Yield a SetLoop.
        r   startr\   N)rb   rc   get_value_typer   intpr   r3   r   rm   r   r   r   r]   r2   r/   r   r[   r_   )rh   r   r   r   r   r   sizeZ
range_loopr^   is_usedloopr#   r#   r$   _iterate7  s$   "z_SetPayload._iteratec                 c   s   | j }| j}|tj}t|d}t|d}| j}|d}|d}t	
|| j}	|| ||0 ||	}
||||
|}
||
|	 | |
}t|||j}|||| W d   n1 sjw   Y  || ||	}
|
| _| |
V  dS )z
        Yield a random entry from the payload.  Caller must ensure the
        set isn't empty, otherwise the function won't end.
        r   r   Znext_entry_bodyZnext_entry_endN)rb   rc   r   r   r   r   r3   rm   r   r   r   rx   r   r   r   r   r   r   r   r2   r/   cbranchr   )rh   r   r   r   zeror   rm   r   r   r]   r   r^   r   r#   r#   r$   _next_entryK  s.   





	
z_SetPayload._next_entryFrk   )__name__
__module____qualname__ri   propertyrm   setterrs   rv   rx   rz   ra   r    r   r   
contextlibcontextmanagerr   r   r#   r#   r#   r$   r`   u   s@    	













vr`   c                   @   s  e Zd Zdd Zedd Zedd Zedd Zed	d
 Zedd Z	e	j
dd Z	dd Zdd ZdUddZdVddZdVddZdUddZdUddZdUddZdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 ZdWd2d3Zd4d5 Zd6d7 ZedXd9d:Z edXd;d<Z!ed=d> Z"ed?d@ Z#dAdB Z$dCdD Z%dEdF Z&dGdH Z'dWdIdJZ(dKdL Z)dMdN Z*dOdP Z+dQdR Z,dSdT Z-d8S )YSetInstancec                 C   s2   || _ || _|| _t||| _||||| _d S rk   )rb   rc   rd   r(   
_entrysizemake_helper_set)rh   r   r   r   set_valr#   r#   r$   ri   v  s
   zSetInstance.__init__c                 C   rj   rk   )rd   rV   rn   r#   r#   r$   rV   }  ro   zSetInstance.dtypec                 C   s.   | j }| j}| j j|| j}t||| j|S )z/
        The _SetPayload for this set.
        )rb   rc   nrtmeminfo_datameminfor`   rd   )rh   r   r   r    r#   r#   r$   r"     s   zSetInstance.payloadc                 C   
   | j  S rk   )r   	_getvaluern   r#   r#   r$   r8        
zSetInstance.valuec                 C   rj   rk   )r   r   rn   r#   r#   r$   r     ro   zSetInstance.meminfoc                 C   rj   rk   r   parentrn   r#   r#   r$   r     ro   zSetInstance.parentc                 C   rp   rk   r   rq   r#   r#   r$   r     rt   c                 C   rj   )z<
        Return the number of elements in the size.
        )r"   rs   rn   r#   r#   r$   get_size  s   zSetInstance.get_sizec                 C   s$   | j jr|r	tjntj| j_d S d S rk   )rd   Z	reflectedr   r   r   r"   rz   rh   valr#   r#   r$   	set_dirty  s   zSetInstance.set_dirtyTc                 C   s   | j }| j}|j}||_| | ||_|j}	t|	jd}
|	|	|
 }	|_|j
t|||dd |	|j|
|_W d    n1 sEw   Y  |rQ| |	 | d d S )Nr   TZlikely)rb   rc   r/   incref_valuer   rs   r   r3   r4   r   r   rJ   rv   upsizer   )rh   r"   r^   r   r=   	do_resizer   r   old_hashrs   r   r#   r#   r$   
_add_entry  s"   

zSetInstance._add_entryc              	   C   s  | j }| j}|j||dd\}}	||}
||
` ||	}|j}||_|r-| | ||_|j	}t
|jd}||| }|_	|jt|||dd ||j||_W d    n1 saw   Y  |rm| | | d W d    d S 1 s}w   Y  d S )NTr   r   r   )rb   rc   r   not_r   r   r/   r   r   rs   r   r3   r4   r   rJ   rv   r   r   )rh   r"   r   r=   r   	do_increfr   r   r   r   	not_foundr^   r   rs   r   r#   r#   r$   _add_key  s.   



"zSetInstance._add_keyc                 C   sf   t |jjt|_|r| |j |j}t |jd}| j	|| }|_|r,| 
| | d d S )Nr   T)r   r3   r/   r4   rM   decref_valuer   rs   rc   subdownsizer   )rh   r"   r^   r   	do_decrefrs   r   r#   r#   r$   _remove_entry  s   
zSetInstance._remove_entryc           
      C   sd   | j }| j}|||\}}|| ||}	| ||	| W d    |S 1 s+w   Y  |S rk   )rb   rc   r   r   r   r   )
rh   r"   r   r=   r   r   r   r   r   r^   r#   r#   r$   _remove_key  s   

zSetInstance._remove_keyc                 C   s8   | j }| j}| j}t||| jj|}| |||| d S rk   )rb   rc   r"   r?   rd   rV   r   )rh   r   r   r   r   r"   r=   r#   r#   r$   r     s
   zSetInstance.addc                 C   s6   | j }| j}| j}| ||||}| |||| dS )z`A version of .add for use inside functions following Python calling
        convention.
        N)rb   rc   r"   _pyapi_get_hash_valuer   )rh   pyapir   r   r   r   r"   r=   r#   r#   r$   	add_pyapi  s
   zSetInstance.add_pyapic                 C   s   | j jg}tj}dd }|g}tj|g|R  }	|||	|\}
}|j|
dd ||	  W d   |S 1 s;w   Y  |S )z=Python API compatible version of `get_hash_value()`.
        c                 S      t | S rk   )rD   )r   r#   r#   r$   wrapper     z2SetInstance._pyapi_get_hash_value.<locals>.wrapperFr   N)
rd   rV   r   r   r   	signatureZcall_jit_coder   retZget_null_object)rh   r   r   r   r   argtypesZrestyr   rA   r;   Zis_errorretvalr#   r#   r$   r     s   

z!SetInstance._pyapi_get_hash_valuec                 C   s8   | j }| j}| j}t||| jj|}|||\}}|S rk   )rb   rc   r"   r?   rd   rV   r   )rh   r   r   r   r"   r=   r   r   r#   r#   r$   contains  s   zSetInstance.containsc                 C   s6   | j }| j}| j}t||| jj|}| |||}|S rk   )rb   rc   r"   r?   rd   rV   r   )rh   r   r   r   r"   r=   r   r#   r#   r$   discard   s   zSetInstance.discardc                 C   s|   | j }| j}|| jj}t||}| j}| }|	|j
| | j||dd W d    n1 s4w   Y  ||S )NF)r   )rb   rc   r   rd   rV   r   Zalloca_oncer"   r   r   r   r   r   )rh   r   r   Zltyr   r"   r^   r#   r#   r$   pop)  s   

zSetInstance.popc                 C   s<   | j }| j}|tj}t|t}| | | 	d d S )NT)
rb   rc   r   r   r   r   r3   MINSIZE_replace_payloadr   )rh   r   r   r   minsizer#   r#   r$   clear8  s   
zSetInstance.clearc              
   C   s  | j }| j}| j}|j}|j}t| ||| jd}|d||}|j|dd\}}	|/ |	|}
|j
||
dd |j|td W d   n1 sOw   Y  W d   n1 s^w   Y  |	[ | |||}||}
|j
||
dd |j|td W d   n1 sw   Y  |j}| }|j}|j||j|jdd W d   n1 sw   Y  W d   n1 sw   Y  W d   |S W d   |S 1 sw   Y  |S )z,
        Return a copy of this set.
        NrF   Tr   F)zcannot copy setr   )rb   rc   r"   rs   rv   r4   rd   rH   if_else_copy_payloadr   r   	call_convreturn_user_excMemoryErrorchoose_alloc_size_allocate_payloadr   r^   r   r   r/   )rh   r   r   r"   rs   rv   otherZno_deleted_entriesZif_no_deletedZ
if_deletedoknentriesother_payloadr   r^   r#   r#   r$   copyA  sT   






zSetInstance.copyc           
   	   C   s   | j }| j}| j}|j}| 5}|j}||j|j\}}	||	| | j
||dd W d   n1 s9w   Y  W d   n1 sHw   Y  | |j dS )z9
        In-place intersection with *other* set.
        Fr   N)rb   rc   r"   r   r^   r   r   r/   r   r   r   r   rs   )
rh   r   r   r   r"   r   r   r^   r   _r#   r#   r$   	intersecth  s   
zSetInstance.intersectc                 C   sl   | j }| j}| j}|j}| }|j}| j||j|jdd W d   n1 s)w   Y  | |j	 dS )z7
        In-place difference with *other* set.
        Fr   N)
rb   rc   r"   r   r^   r   r   r/   r   rs   )rh   r   r   r   r"   r   r   r^   r#   r#   r$   
differencez  s   
zSetInstance.differencec              
   C   s  | j }| j}|j}| m}|jj}|jj}| j}|j||dd\}	}
||
}|	|	>\}}| | j
||dd W d   n1 sEw   Y  | | |||| W d   n1 s_w   Y  W d   n1 snw   Y  W d   n1 s}w   Y  | | jj dS )zA
        In-place symmetric difference with *other* set.
        Tr   Fr   N)rb   rc   r"   r   r^   r   r/   r   r   r   r   r   r   rs   )rh   r   r   r   r   r   r   r=   r"   r   r   r^   Z	if_commonZif_not_commonr#   r#   r$   symmetric_difference  s*   

z SetInstance.symmetric_differenceFc                 C   sV  | j }| j}| j}|j}|rdnd}t|tj}||||j|jy\}	}
|
 |	tj
| W d    n1 s<w   Y  |	L | 8}|j}||j|j\}}||| |	tj
| |  W d    n1 stw   Y  W d    n1 sw   Y  W d    n1 sw   Y  W d    n1 sw   Y  ||S )NrP   <=)rb   rc   r"   r   r   r   r   rH   rs   r   r   r   r^   r   r   r/   r   r   r_   r   )rh   r   strictr   r   r"   r   cmp_opresZ
if_smaller	if_largerr   r^   r   r   r#   r#   r$   issubset  s8   


zSetInstance.issubsetc              	      s   | j }| j | j}|j}t tj fdd}  d|j|j8\}}| ||| W d    n1 s;w   Y  | ||| W d    n1 sRw   Y  W d    n1 saw   Y   	S )Nc              	      s   |   >}|j}||j|j\}} |  tj |	  W d    n1 s-w   Y  W d    d S W d    d S 1 sEw   Y  d S rk   )
r   r^   r   r   r/   r   r   r   r   r_   )ZsmallerZlargerr   r^   r   r   r   r   r#   r$   check  s   

"z%SetInstance.isdisjoint.<locals>.check>)
rb   rc   r"   r   r   r   r   rH   rs   r   )rh   r   r   r"   r   r  r   	otherwiser#   r  r$   
isdisjoint  s&   	
zSetInstance.isdisjointc                 C   sJ  | j }| j}| j}|j}t|tj}||d|j|jy\}}|L |	 8}	|	j
}
||
j|
j\}}||| |tj| |	  W d    n1 sUw   Y  W d    n1 sdw   Y  W d    n1 ssw   Y  | |tj| W d    n1 sw   Y  W d    n1 sw   Y  ||S )NrF   )rb   rc   r"   r   r   r   r   rH   rs   r   r^   r   r   r/   r   r   r   r   r_   r   )rh   r   r   r   r"   r   r   Zif_same_sizer  r   r^   r   r   r#   r#   r$   equals  s6   


zSetInstance.equalsNc           	      C   sf   | tj}|du rt|t}nt|trt||}| |||}| |||d}|	|}||fS )z
        Allocate a SetInstance with its storage.
        Return a (ok, instance) tuple where *ok* is a LLVM boolean and
        *instance* is a SetInstance object (the object's contents are
        only valid when *ok* is true).
        N)
r   r   r   r   r3   r   rQ   intr   r   )	clsr   r   r   nitemsr   r   rh   r   r#   r#   r$   allocate_ex  s   

zSetInstance.allocate_exc                 C   s^   |  ||||\}}|j||dd |j|td W d   |S 1 s(w   Y  |S )z
        Allocate a SetInstance with its storage.  Same as allocate_ex(),
        but return an initialized *instance*.  If allocation failed,
        control is transferred to the caller using the target's current
        call convention.
        Fr   )zcannot allocate setN)r
  r   r   r   r   r   )r  r   r   r   r	  r   rh   r#   r#   r$   allocate  s   

zSetInstance.allocatec                 C   s<   | |||d}||j _|tj|j _|j|||j |S )z
        Allocate a new set instance pointing to an existing payload
        (a meminfo pointer).
        Note the parent field has to be filled by the caller.
        N)	r   r   get_constant_nullr   pyobjectr   r   increfr8   )r  r   r   r   r   rh   r#   r#   r$   from_meminfo  s
   zSetInstance.from_meminfoc              	   C   s  |j }t|d}t|t}|||}t||}|d}	|d}
||	 |	|	A |
|}|d||}|j|dd ||
 W d   n1 sSw   Y  |||}||| ||	 W d   n1 ssw   Y  ||
 |
|S )zT
        Choose a suitable number of entries for the given number of items.
        r   calcsize.bodycalcsize.end>=Fr   N)r4   r   r3   r   shlr   r   r   r   r   r   rH   r   r   r   )r  r   r   r	  r   r   r   min_entriesZsize_pr   r   r   Zis_large_enoughZ	next_sizer#   r#   r$   r   $  s(   




	
zSetInstance.choose_alloc_sizec              	   C   sX  | j }| j}|j}t|d}t|d}| j}|||}||j|}	|	d||	}
|j
|
ddo t||	}|d}|d}|| ||' ||}|||}||| |	d||}|||| W d   n1 sxw   Y  || ||}tr||d	||	|| | ||d
 W d   dS 1 sw   Y  dS )zs
        When adding to the set, ensure it is properly sized for the given
        number of used entries.
        r      r  Fr   r  r  NzKupsize to %zd items: current size = %zd, min entries = %zd, new size = %zd
zcannot grow set)rb   rc   r4   r   r3   r"   r  r   rm   rH   r   r   r   r   r   r   r   r   r   r   DEBUG_ALLOCSprintf_resize)rh   r	  r   r   r   r   twor"   r  r   need_resize
new_size_pr   r   new_sizeis_too_smallr#   r#   r$   r   C  s<   





"zSetInstance.upsizec              
   C   s  | j }| j}|j}t|d}t|d}t|t}| j}|||}	||	d|	||	|}	||	|}
|
|j|}||	d|
||	d||}|j|dd t||}|d}|d	}|| ||? ||}|||}|	d
|	|}|| || W d   n1 sw   Y  ||| || W d   n1 sw   Y  || ||}tr||d|||	| | ||d W d   dS 1 sw   Y  dS )zw
        When removing from the set, ensure it is properly sized for the given
        number of used entries.
        r   r  r  r   rP   Fr   r  r  r  NzMdownsize to %zd items: current size = %zd, min entries = %zd, new size = %zd
zcannot shrink set)rb   rc   r4   r   r3   r   r"   r  r6   rH   r   rm   r   r   r   r   r   r   r   r   r   r   r   r  r  r  )rh   r	  r   r   r   r   r  r   r"   r  max_sizer   r  r  r   r   r  r  r#   r#   r$   r   q  sR   





"zSetInstance.downsizec           
      C   s   | j }| j}|}| j|dd}|j||dd |j|t|f W d   n1 s-w   Y  | j}|	 }|j
}	| j||	j|	jddd W d   n1 sSw   Y  | |j dS )zw
        Resize the payload to the given number of entries.

        CAUTION: *nentries* must be a power of 2!
        TreallocFr   N)r   r   )rb   rc   r   r   r   r   r   r   r"   r   r^   r   r   r/   _free_payloadr    )
rh   r"   r   errmsgr   r   Zold_payloadr   r   r^   r#   r#   r$   r    s"   

zSetInstance._resizec                 C   s   | j }| j}| j }|j}| |j W d   n1 sw   Y  | | jj | j	|dd}|j
||dd |j|td W d   dS 1 sPw   Y  dS )z
        Replace the payload with a new empty payload with the given number
        of entries.

        CAUTION: *nentries* must be a power of 2!
        NTr  Fr   )zcannot reallocate set)rb   rc   r"   r   r^   r   r   r!  r    r   r   r   r   r   r   )rh   r   r   r   r   r^   r   r#   r#   r$   r     s   
"zSetInstance._replace_payloadc              
   C   sd  | j }| j}t|tj}|tj}t	|d}t	|d}|
t| j}	||	}
| j}|
|8 }
t||t	||t	||
\}}|j|dd |tj| W d   n1 s_w   Y  |j||dd |r| jj}|jj|||d}t||}n| ||j}|j||||tj}t||}|j|ddn\}}| |tj| W d   n1 sw   Y  |@ |s|| j_|tj | j_!| j"}t#||j$|d ||_%||_&||_'|(||}||_)t*r|+|d	||j$| W d   n	1 sw   Y  W d   n	1 sw   Y  W d   n	1 s(w   Y  ||S )
z
        Allocate and initialize payload for the given number of entries.
        If *realloc* is True, the existing meminfo is reused.

        CAUTION: *nentries* must be a power of 2!
        r   r   Fr   NT)r      .allocated %zd bytes for set at %p: mask = %zd
),rb   rc   r   r   r   r   r   r   r   r3   r   r   rd   r'   r   Zmuladd_with_overflowr   r   r   r   r   r   r   Zmeminfo_varsize_alloc_uncheckedis_null	_imp_dtormodule"meminfo_new_varsize_dtor_uncheckedr   	voidptr_tr   r  r  r   r"   Zmemsetr    rs   rv   rx   r   rm   r  r  )rh   r   r   r   r   r   r   r   r   r!   payload_size
entry_size	allocsizeZovfr   r    alloc_okdtorif_errorif_okr"   Znew_maskr#   r#   r$   r     sx   



$zSetInstance._allocate_payloadc                 C   s   | j j| j| j| dS )z9
        Free an allocated old payload at *ptr*.
        N)rb   r   Zmeminfo_varsize_freerc   r   )rh   r    r#   r#   r$   r!  "  s   zSetInstance._free_payloadc                 C   s(  | j }| j}t|tj}|tj}t	|d}t	|d}|
t| j}||}	| j}
|	|
8 }	|j}|||}|t	||	|t	||
|}|j||dd | ||j}|j||||tj}t||}|j|dd|\}}| |tj| W d   n1 sw   Y  |O || j_| j }|j!|_!|j"|_"||_#||_t$||j%|j%||
 |& }| '|j(j) W d   n1 sw   Y  t*r|+|d||j,| W d   n1 sw   Y  W d   n1 sw   Y  W d   n	1 s
w   Y  ||S )z7
        Raw-copy the given payload into self.
        r   r   Tr   FNr$  )-rb   rc   r   r   r   r   r   r   r   r3   r   r   rd   r'   r   rm   r   r   r   r   r&  r'  r   r(  r   r)  r%  r   r   r   r   r   r"   rs   rv   rx   Z
raw_memcpyra   r   r   r^   r   r  r  r    )rh   Zsrc_payloadr   r   r   r   r   r   r!   r*  r+  rm   r   r,  r.  r   r-  r/  r0  r"   r   r#   r#   r$   r   (  sj   



"zSetInstance._copy_payloadc                 C   s   t j}|tj}tt |||g}d| jj	 }t j
|||d}|jrad|_t| }t||| j|jd }	|	 }
|
j}|j|| jj	|j W d   n1 sXw   Y  |  |S )z Define the dtor for set
        z
.dtor.set.)nameZlinkonce_odrr   N)r   r)  r   r   Zsize_tr   FunctionTypeZVoidTyperd   rV   Zget_or_insert_functionZis_declarationlinkageZ	IRBuilderr   r`   rA   r   r^   r   decrefr   Zret_void)rh   r   r'  Z	llvoidptrZllsize_tr:   fnamer<   r   r"   r   r^   r#   r#   r$   r&  i  s$   
zSetInstance._imp_dtorc                 C      | j j| j| jj| dS )z Incref an element value
        N)rb   r   r  rc   rd   rV   r   r#   r#   r$   r        zSetInstance.incref_valuec                 C   r6  )z Decref an element value
        N)rb   r   r4  rc   rd   rV   r   r#   r#   r$   r     r7  zSetInstance.decref_value)T)TTr   rk   ).r   r   r   ri   r   rV   r"   r8   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  classmethodr
  r  r  r   r   r   r  r   r   r!  r   r&  r   r   r#   r#   r#   r$   r   t  sh    











			'


.<
CAr   c                   @   sZ   e Zd Zdd Zedd Zedd Zedd Zed	d
 Z	e	j
dd
 Z	dd ZdS )SetIterInstancec                 C   sL   || _ || _|| _||||| _| j j|| j}t||| jj	|| _
d S rk   )rb   rc   rd   r   _iterr   r   r   r`   	containerre   )rh   r   r   	iter_typeZiter_valr    r#   r#   r$   ri     s   zSetIterInstance.__init__c                 C   sJ   t |||j|}| |||d }|tjd}t|||j_|j	|j_	|S r@   )
r   r;  get_constantr   r   r   r   r:  r]   r   )r  r   r   r<  r   Zset_instrh   r]   r#   r#   r$   from_set  s   
zSetIterInstance.from_setc                 C   r   rk   )r:  r   rn   r#   r#   r$   r8     r   zSetIterInstance.valuec                 C   rj   rk   )r:  r   rn   r#   r#   r$   r     ro   zSetIterInstance.meminfoc                 C   s   | j | jjS rk   )rc   r   r:  r]   rn   r#   r#   r$   r]     s   zSetIterInstance.indexc                 C   s   | j || jj d S rk   )rc   r   r:  r]   rq   r#   r#   r$   r]     s   c                 C   s   | j }| j}t|jd}|  |j|d#}|j}|  |	|j
 | j|j || _ |  W d    d S 1 s=w   Y  d S )Nr   r   )r]   re   r   r3   r4   Zset_exhaustedr   r^   Z	set_validZyield_r   rc   r   r_   )rh   resultr]   r"   r   r   r^   r#   r#   r$   iternext  s   
"zSetIterInstance.iternextN)r   r   r   ri   r8  r>  r   r8   r   r]   r   r@  r#   r#   r#   r$   r9    s    




r9  c              	   C   s   t |}t| |||}|dkrJt||}t||}| tj|}t	||}	|
t||d|	j}
||
 W d   n1 sEw   Y  t| |||jS )zD
    Build a set of the given type, containing the given items.
    r   N)lenr   r  r   Z
pack_arrayr   r=  r   r   r   r   r}   r]   r   r   r8   )r   r   r   itemsr	  instarrayZ	array_ptrcountr   r   r#   r#   r$   	build_set  s   rF  c                 C   s$   |j }t| ||}t| |||jS rk   )return_typer   r  r   r8   )r   r   r;   rA   r   rC  r#   r#   r$   set_empty_constructor  s   rH  c           
      C   s   |j }|j\}|\}t| |||}t| |||}t| |||}	||	j | j	||j
|	j W d    n1 s;w   Y  t| |||jS rk   )rG  rA   r   r   r  r   r   r8   r   r4  rV   r   )
r   r   r;   rA   r   
items_typerB  nrC  r   r#   r#   r$   set_constructor  s   rK  c                 C   s    t | ||jd |d }| S r@   )r   rA   r   r   r   r;   rA   rC  r#   r#   r$   set_len  s   rM  c                 C   s&   t | ||jd |d }||d S Nr   r   )r   rA   r   rL  r#   r#   r$   in_set  s   rO  Zgetiterc                 C   s(   t | ||j|d }t| ||j|jS r@   )r9  r>  rG  r
   r8   rL  r#   r#   r$   getiter_set  s   rP  r@  c                 C   s&   t | ||jd |d }|| d S r@   )r9  rA   r@  )r   r   r;   rA   r?  rC  r#   r#   r$   iternext_listiter	  s   rQ  zset.addc                 C   2   t | ||jd |d }|d }|| |  S rN  )r   rA   r   get_dummy_valuer   r   r;   rA   rC  r   r#   r#   r$   set_add  s   
rU  c                 C      t ||}dd }||fS )Nc                 S   rR  rN  )r   rA   r   rS  rT  r#   r#   r$   set_discard"  s   
z!_set_discard.<locals>.set_discardr   none)r9   rW   r   r;   rW  r#   r#   r$   _set_discard  s   rZ  r   c                 C      dd S )Nc                 S   
   t | |S rk   )rZ  rW   r   r#   r#   r$   <lambda>.     
 z ol_set_discard.<locals>.<lambda>r#   r]  r#   r#   r$   ol_set_discard,  ro   r`  c                 C   s   | |}dd }||fS )Nc                 S   st   t | ||jd |d }|jj}|jt||dd | j|t	d W d    |
 S 1 s1w   Y  |
 S )Nr   Fr   )zset.pop(): empty set)r   rA   r"   rs   r   r   r%  r   r   KeyErrorr   )r   r   r;   rA   rC  rs   r#   r#   r$   set_pop5  s   

z_set_pop.<locals>.set_poprU   )r9   rW   r;   rb  r#   r#   r$   _set_pop1  s   
	rc  r   c                 C   r[  )Nc                 S   r   rk   )rc  rW   r#   r#   r$   r^  C      zol_set_pop.<locals>.<lambda>r#   rd  r#   r#   r$   
ol_set_popA  ro   rf  c                 C   rV  )Nc                 S   s|   t | ||jd |d }|d }||}|j||dd | j|td W d    |  S 1 s5w   Y  |  S )Nr   r   Fr   )zset.remove(): key not in set)	r   rA   r   r   r   r   r   ra  rS  )r   r   r;   rA   rC  r   r   r#   r#   r$   
set_removeJ  s   


z_set_remove.<locals>.set_removerX  )r9   rW   r   r;   rg  r#   r#   r$   _set_removeF  s   
rh  removec                 C   s   | j |kr	dd S d S )Nc                 S   r\  rk   )rh  r]  r#   r#   r$   r^  Z  r_  zol_set_remove.<locals>.<lambda>rU   r]  r#   r#   r$   ol_set_removeW  s   
rj  c                 C   s   t |}dd }||fS )Nc                 S   s(   t | ||jd |d }|  |  S r@   )r   rA   r   rS  rL  r#   r#   r$   	set_clearc  s   z_set_clear.<locals>.set_clearrX  )r9   rW   r;   rk  r#   r#   r$   
_set_clear_  s   
rl  r   c                 C   r[  )Nc                 S   r   rk   )rl  rd  r#   r#   r$   r^  m  re  zol_set_clear.<locals>.<lambda>r#   rd  r#   r#   r$   ol_set_cleark  ro   rm  c                 C   s   ||}dd }||fS )Nc                 S   s2   t | ||jd |d }| }t| ||j|jS r@   )r   rA   r   r   rG  r8   r   r   r;   rA   rC  r   r#   r#   r$   set_copyt  s   z_set_copy.<locals>.set_copyr#   )r9   rW   r;   ro  r#   r#   r$   	_set_copyp  s   rp  r   c                 C   r[  )Nc                 S   r   rk   )rp  rd  r#   r#   r$   r^  ~  re  zol_set_copy.<locals>.<lambda>r#   rd  r#   r#   r$   ol_set_copy|  ro   rq  c                 C   B   t | ||jd |d }t | ||jd |d }|| |  S rN  )r   rA   r   rS  rn  r#   r#   r$   set_difference_update  s   
rs  c                 C      t ||}|tfS rk   )r   rY  rs  r9   abr;   r#   r#   r$   _set_difference_update     rx  difference_updatec                 C      t | | dd S )Nc                 S   r\  rk   )rx  rv  rw  r#   r#   r$   r^    r_  z,set_difference_update_impl.<locals>.<lambda>rZ   r|  r#   r#   r$   set_difference_update_impl     
r~  c                 C   rr  rN  )r   rA   r   rS  rn  r#   r#   r$   set_intersection_update     
r  c                 C   rt  rk   )r   rY  r  ru  r#   r#   r$   _set_intersection_update  ry  r  intersection_updatec                 C   r{  )Nc                 S   r\  rk   )r  r|  r#   r#   r$   r^    r_  z.set_intersection_update_impl.<locals>.<lambda>r}  r|  r#   r#   r$   set_intersection_update_impl  r  r  c                 C   rr  rN  )r   rA   r   rS  rn  r#   r#   r$   set_symmetric_difference_update  r  r  c                 C   rt  rk   )r   rY  r  ru  r#   r#   r$    _set_symmetric_difference_update  ry  r  symmetric_difference_updatec                 C   r{  )Nc                 S   r\  rk   )r  r|  r#   r#   r$   r^    r_  z6set_symmetric_difference_update_impl.<locals>.<lambda>r}  r|  r#   r#   r$   $set_symmetric_difference_update_impl  r  r  z
set.updatec                 C   s   t | ||jd |d }|jd }|d }t| |||}|d ur-||jj|}|| t| |||"}	| ||	j	|j
|j
}
||
 | j||j
|	j	 W d    n1 sYw   Y  |d uri||jj |  S rN  )r   rA   r   r   r"   rs   r   r   castr8   rV   r   r4  r   rS  )r   r   r;   rA   rC  rI  rB  rJ  r  r   Zcastedr#   r#   r$   
set_update  s   


r  c                    s(   t fdd t|  fdd}d S )Nc                    s   |||} fdd}||fS )Nc                    s:   |j |jd ks
J  | ||| t| ||jd |d S r@   )rG  rA   r
   )r   r   r;   rA   rC   r#   r$   codegen  s   z>gen_operator_impl.<locals>._set_operator_intr.<locals>.codegenr#   r9   rv  rw  r;   r  r  r#   r$   _set_operator_intr  s   
z-gen_operator_impl.<locals>._set_operator_intrc                    s   t | |  fddS )Nc                    s
    | |S rk   r#   r|  r  r#   r$   r^    r_  z=gen_operator_impl.<locals>._ol_set_operator.<locals>.<lambda>r}  r|  r  r#   r$   _ol_set_operator  s   
z+gen_operator_impl.<locals>._ol_set_operator)r   r   )oprC   r  r#   )r  rC   r$   gen_operator_impl  s   r  r   c                 C      t | | dd }|S )Nc                 S   s   |   }|| |S rk   )r   rz  rv  rw  rW   r#   r#   r$   difference_impl  s   
z,impl_set_difference.<locals>.difference_implr}  )rv  rw  r  r#   r#   r$   impl_set_difference  s   
r  intersectionc                 C   r  )Nc                 S   s<   t | t |k r|  }|| |S | }||  |S rk   )rA  r   r  r  r#   r#   r$   intersection_impl     

z+set_intersection.<locals>.intersection_implr}  )rv  rw  r  r#   r#   r$   set_intersection     

r  r   c                 C   r  )Nc                 S   <   t | t |kr|  }|| |S | }||  |S rk   )rA  r   r  r  r#   r#   r$   symmetric_difference_impl  r  z;set_symmetric_difference.<locals>.symmetric_difference_implr}  )rv  rw  r  r#   r#   r$   set_symmetric_difference  r  r  unionc                 C   r  )Nc                 S   r  rk   )rA  r   updater  r#   r#   r$   
union_impl(  r  zset_union.<locals>.union_implr}  )rv  rw  r  r#   r#   r$   	set_union#  r  r  c                 C   rV  )Nc                 S   :   t | ||jd |d }t | ||jd |d }||S rN  )r   rA   r  rn  r#   r#   r$   r  ;     
z _set_isdisjoint.<locals>.codegenr   booleanr  r#   r#   r$   _set_isdisjoint7     r  r  c                 C   r{  )Nc                 S   r\  rk   )r  r|  r#   r#   r$   r^  H  r_  z set_isdisjoint.<locals>.<lambda>r}  r|  r#   r#   r$   set_isdisjointD     
r  c                 C   rV  )Nc                 S   r  rN  r   rA   r   rn  r#   r#   r$   r  O  r  z_set_issubset.<locals>.codegenr  r  r#   r#   r$   _set_issubsetK  r  r  r   c                 C   r{  )Nc                 S   r\  rk   )r  r|  r#   r#   r$   r^  \  r_  zset_issubset.<locals>.<lambda>r}  r|  r#   r#   r$   set_issubsetW  s   
r  
issupersetc                 C   r  )Nc                 S   s
   | | S rk   )r   r|  r#   r#   r$   superset_impld     
z%set_issuperset.<locals>.superset_implr}  )rv  rw  r  r#   r#   r$   set_issuperset_  s   
r  c                 C   rV  )Nc                 S   r  rN  )r   rA   r  rn  r#   r#   r$   r  m  r  z_set_eq.<locals>.codegenr  r  r#   r#   r$   _set_eqi  r  r  c                 C   r{  )Nc                 S   r\  rk   )r  r|  r#   r#   r$   r^  y  r_  zset_eq.<locals>.<lambda>r}  r|  r#   r#   r$   set_equ  r  r  c                 C   r  )Nc                 S   s
   | |k S rk   r#   r|  r#   r#   r$   ne_impl  r  zset_ne.<locals>.ne_implr}  )rv  rw  r  r#   r#   r$   set_ne{     
r  c                 C   rV  )Nc                 S   s>   t | ||jd |d }t | ||jd |d }|j|ddS )Nr   r   T)r   r  rn  r#   r#   r$   r    s   z_set_lt.<locals>.codegenr  r  r#   r#   r$   _set_lt  r  r  c                 C   r{  )Nc                 S   r\  rk   )r  r|  r#   r#   r$   r^    r_  zset_lt.<locals>.<lambda>r}  r|  r#   r#   r$   set_lt  r  r  c                 C   r  )Nc                 S   s   || k S rk   r#   r|  r#   r#   r$   gt_impl  r   zset_gt.<locals>.gt_implr}  )rv  rw  r  r#   r#   r$   set_gt  r  r  c                 C   s^   t | ||jd |d }t | ||jd |d }||jtj}||jtj}|d||S )Nr   r   rF   )r   rA   Zptrtointr   r   r   Zicmp_signed)r   r   r;   rA   rv  rw  mambr#   r#   r$   set_is  s
   r  c                 C   s   |j |j ksJ |S rk   rU   )r   r   ZfromtyZtotyr   r#   r#   r$   
set_to_set  s   r  )}__doc__collectionsr   mathr   	functoolsr   Zllvmliter   Z
numba.corer   r   r   Znumba.core.imputilsr   r   r	   r
   r   r   r   r   r   Z
numba.miscr   Znumba.cpythonr   Znumba.core.errorsr   r   Znumba.core.extendingr   r   r   r%   r(   rG   rM   r5   r   r   r  r?   rD   rJ   rO   r2   rZ   
namedtupler[   objectr`   r   r9  rF  setrH  ZIterableTyperK  rA  rR   rM  r   AnyrO  rP  ZSetIterZBORROWEDrQ  rU  rZ  r`  rc  rf  rh  rj  rl  rm  rp  rq  rs  rx  r~  r  r  r  r  r  r  r  r  iandiorisubixorZop_Zop_implr   r  r   r  xorr  or_r  r  r  r  ler  ger  r  r   r  ner  r  ltr  gtr  is_r  r  r#   r#   r#   r$   <module>   s   ,
	        "6

























	



























