+
    :i߂                         R t ^ RIt^ RIHt ]P                  ! RR
4      t^Ut^tRt]P                  ! RR4      t	]P                  ! RR4      t
R tR tR	 tR# )z
Timsort implementation.  Mostly adapted from CPython's listobject.c.

For more information, see listsort.txt in CPython's source tree.
N)typesTimsortImplementation   
MergeStateMergeRunc                   aaaaaaa	a
aaaaaaaaaaaaaaaaaa V ! S4      o\         P                  oS! ^ 4      oV R 4       o
V VVV3R l4       oV VVV3R l4       oV R 4       oV R 4       oV V
V3R l4       oV V3R l4       oV R 4       oV VV
3R	 l4       oV V3R
 l4       oV V3R l4       oV V3R l4       o	V R 4       oV V
3R l4       oV V
3R l4       o^oV VVVV	V
VVV3R l4       oV VVVV	V
VVVV3	R l4       oV VV	VVV3R l4       oV V3R l4       oV V3R l4       oV V
3R l4       oV VVVVVVVV3R l4       oV VV3R l4       pV VV3R l4       p\        V SSSS	SSSSSSSSSW#4      # )    c                     WJ# N )keysvaluess   &&P/var/www/html/photoedit/myenv/lib/python3.14/site-packages/numba/misc/timsort.py
has_values%make_timsort_impl.<locals>.has_values?   s    !!    c                   < \        \        V 4      ^,          ^,           \        4      pS! W4      pTp\        SS4      .\        ,          p\        S! \        4      W#VS4      # )z/
Initialize a MergeState for a non-keyed sort.
minlenMERGESTATE_TEMP_SIZEr   MAX_MERGE_PENDINGr   
MIN_GALLOP)r   	temp_size	temp_keystemp_valuespendingintpmake_temp_areazeros   &    r   
merge_init%make_timsort_impl.<locals>.merge_initC   sY    
 D	Q*,@A	"43	D$'(+<<$z*IGTRRr   c                   < \        \        V 4      ^,          ^,           \        4      pS! W4      pS! W4      p\        SS4      .\        ,          p\        S! \        4      W4VS4      # )z+
Initialize a MergeState for a keyed sort.
r   )	r   r   r   r   r   r   r   r   r   s	   &&    r   merge_init_with_values1make_timsort_impl.<locals>.merge_init_with_valuesN   s^    
 D	Q*,@A	"43	$V7D$'(+<<$z*IGTRRr   c                    V P                   pV\        8  g   Q hWP                  V&   \        V P                  V P
                  V P                  V P                  V^,           4      # )z"
Append a run on the merge stack.
)nr   r   r   
min_gallopr   r   )msrunr&   s   && r   merge_append'make_timsort_impl.<locals>.merge_appendY   sN    
 DD$$$$

1"--"))RZZQOOr   c                    \        V P                  V P                  V P                  V P                  V P
                  ^,
          4      # )z'
Pop the top run from the merge stack.
)r   r'   r   r   r   r&   )r(   s   &r   	merge_pop$make_timsort_impl.<locals>.merge_popc   s0    
 "--"))RZZPQRRr   c                P  < \        V P                  4      pW8:  d   V # W!8  d   V^,          pK  S! V P                  V4      pS! V P                  V P                  4      '       d   S! V P                  V4      pMTp\        V P                  W4V P
                  V P                  4      # )z:
Ensure enough temp memory for 'need' items is available.
)r   r   r   r   r'   r   r&   )r(   needallocedr   r   r   r   s   &&   r   merge_getmem'make_timsort_impl.<locals>.merge_getmemj   s    
 bgg,?InlG #277G4	bggryy))(G<K#K"--RTTRRr   c                ~   < \        S! V4      V P                  V P                  V P                  V P                  4      # )z%
Modify the MergeState's min_gallop.
)r   r   r   r   r&   )r(   
new_gallopr   s   &&r   merge_adjust_gallop.make_timsort_impl.<locals>.merge_adjust_gallop~   s-    
 $z*BGGRYY

BDDQQr   c                
    W8  # )zo
Trivial comparison function between two keys.  This is factored out to
make it clear where comparisons occur.
r   )abs   &&r   LTmake_timsort_impl.<locals>.LT   s     ur   c                  < W$8:  d   WC8:  g   Q hS! W4      pW$8X  d
   V^,          pWC8  d   W,          pTpTpWx8  d;   WxV,
          ^,	          ,           p	S! W`V	,          4      '       d   T	pK5  V	^,           pK@  \        WGR4       F  p	W	^,
          ,          W	&   K  	  W`V&   V'       d1   W,          p
\        WGR4       F  p	W^,
          ,          W&   K  	  WV&   V^,          pK  R# )af  
binarysort is the best method for sorting small arrays: it does
few compares, but can do data movement quadratic in the number of
elements.
[lo, hi) is a contiguous slice of a list, and is sorted via
binary insertion.  This sort is stable.
On entry, must have lo <= start <= hi, and that [lo, start) is already
sorted (pass start == lo if you don't know!).
Nrange)r   r   lohistart_has_valuespivotlrp	pivot_valr;   r   s   &&&&&      r   
binarysort%make_timsort_impl.<locals>.binarysort   s     {u{** .;QJEjKE AA
 %a%A&e!W%%A!A 5R(1u+ )G"M	u,A &1uFI -%q	QJEA r   c                  < W8  g   Q hV^,           V8X  d   R# S! W^,           ,          W,          4      '       dS   \        V^,           V4       F1  pS! W,          W^,
          ,          4      '       d   K'  W1,
          R3u # 	  W!,
          R3# \        V^,           V4       F1  pS! W,          W^,
          ,          4      '       g   K'  W1,
          R3u # 	  W!,
          R3# )a~  
Return the length of the run beginning at lo, in the slice [lo, hi).
lo < hi is required on entry.  "A run" is the longest ascending sequence, with

    lo[0] <= lo[1] <= lo[2] <= ...

or the longest descending sequence, with

    lo[0] > lo[1] > lo[2] > ...

A tuple (length, descending) is returned, where boolean *descending*
is set to 0 in the former case, or to 1 in the latter.
For its intended use in a stable mergesort, the strictness of the defn of
"descending" is needed so that the caller can safely reverse a descending
sequence without violating stability (strict > ensures there are no equal
elements to get out of order).
FT)   Fr?   )r   rA   rB   kr;   s   &&& r   	count_run$make_timsort_impl.<locals>.count_run   s    & ww6R<Od6lDH%%262&$'4A;//64<' ' 7D=  262&dgtE{++65=( ' 7E>!r   c                  < W28  g   Q hWB8  d   WC8  g   Q hW2,
          p^ p^pS
! W,          V 4      '       dd   W4,
          pWx8  d=   S
! WV,           ,          V 4      '       d    TpV^,          ^,           pV^ 8:  d   TpK?  KA   Wx8  d   TpWd,          pWt,          pMhWB,
          ^,           pWx8  d=   S
! WV,
          ,          V 4      '       d   MTpV^,          ^,           pV^ 8:  g   K>  TpKB  Wx8  d   TpWG,
          WF,
          rvV^,
          V8:  d   Wg8  d   Ws8:  g   Q hV^,          pWg8  d;   WgV,
          ^,	          ,           p	S
! W,          V 4      '       d   V	^,           pK<  T	pK@  V# )aK  
Locate the proper position of key in a sorted vector; if the vector contains
an element equal to key, return the position immediately to the left of
the leftmost equal element.  [gallop_right() does the same except returns
the position to the right of the rightmost equal element (if any).]

"a" is a sorted vector with stop elements, starting at a[start].
stop must be > start.

"hint" is an index at which to begin the search, start <= hint < stop.
The closer hint is to the final result, the faster this runs.

The return value is the int k in start..stop such that

    a[k-1] < key <= a[k]

pretending that a[start-1] is minus infinity and a[stop] is plus infinity.
IOW, key belongs at index k; or, IOW, the first k elements of a should
precede key, and the last stop-start-k should follow key.

See listsort.txt for info on the method.
r   keyr9   rC   stophintr&   lastofsofsmaxofsmr;   s   &&&&&     r   gallop_left&make_timsort_impl.<locals>.gallop_left   s\   0 ||},,L ags [F,as
mS))!G!8q.Cax$  
 |OGKC \A%F,as
mS)) "G!8q.Cax$|:t~SqyG##+EE 	1m'Ma/0A!$}}a% 
r   c                  < W28  g   Q hWB8  d   WC8  g   Q hW2,
          p^ p^pS
! WV,          4      '       di   WB,
          ^,           pWx8  d<   S
! WWG,
          ,          4      '       d    TpV^,          ^,           pV^ 8:  d   TpK>  K@   Wx8  d   TpWG,
          WF,
          rvMaW4,
          pWx8  d<   S
! WWG,           ,          4      '       d   MTpV^,          ^,           pV^ 8:  g   K=  TpKA  Wx8  d   TpWd,          pWt,          pV^,
          V8:  d   Wg8  d   Ws8:  g   Q hV^,          pWg8  d;   WgV,
          ^,	          ,           p	S
! WV	,          4      '       d   T	pK5  V	^,           pK@  V# )a  
Exactly like gallop_left(), except that if key already exists in a[start:stop],
finds the position immediately to the right of the rightmost equal value.

The return value is the int k in start..stop such that

    a[k-1] <= key < a[k]

The code duplication is massive, but this is enough different given that
we're sticking to "<" comparisons that it's much harder to follow if
written as one routine with yet another "left or right?" flag.
r   rR   s   &&&&&     r   gallop_right'make_timsort_impl.<locals>.gallop_right;  sX    ||},,L cT7 \A%F,cTZ=))!G!8q.Cax$  
 |:t~S [F,cTZ=)) "G!8q.Cax$|OGKCqyG##+EE 	1m'Ma/0A#t}} a%
r   c                j    ^ pV ^ 8  g   Q hV ^@8  d   W^,          ,          pV ^,          p K!  W,           # )a}  
Compute a good value for the minimum run length; natural runs shorter
than this are boosted artificially via binary insertion.

If n < 64, return n (it's too small to bother with fancy stuff).
Else if n is an exact power of 2, return 32.
Else return an int k, 32 <= k <= 64, such that n/k is close to, but
strictly less than, an exact power of 2.

See listsort.txt for more info.
r   )r&   rG   s   & r   merge_compute_minrun/make_timsort_impl.<locals>.merge_compute_minrun  s6     Avv2gQJA!GAur   c                   < V^ 8  g   Q hV^ 8  g   Q h\        V4       F  pW5V,           ,          WV,           &   K  	  S! W44      '       d-   \        V4       F  pWEV,           ,          WV,           &   K  	  R# R# )z
Upwards memcpy().
Nr?   		dest_keysdest_values
dest_startsrc_keys
src_values	src_startnitemsir   s	   &&&&&&& r   sortslice_copy)make_timsort_impl.<locals>.sortslice_copy  o     A~~QvA(0Q(?I1n% h++6].8Q.GN+ # ,r   c                   < V^ 8  g   Q hV^ 8  g   Q h\        V4       F  pW5V,
          ,          WV,
          &   K  	  S! W44      '       d-   \        V4       F  pWEV,
          ,          WV,
          &   K  	  R# R# )z
Downwards memcpy().
Nr?   rc   s	   &&&&&&& r   sortslice_copy_down.make_timsort_impl.<locals>.sortslice_copy_down  rn   r   c           	       < V^ 8  d   V^ 8  d   WF8:  g   Q hWSV,           8X  g   Q hS! W4      p S! V P                   V P                  ^ WVV4       V P                   pV P                  pTp	Tp
Tp^ pS! Wx4      pV P                  pV^ 8  EdS   V^ 8  EdK   ^ p^ p S! W,          Ws,          4      '       dT   W,          W&   V'       d   W,          W+&   V^,          pV^,          pV^,          pV^ 8X  d   MgV^,          p^ pW8  d   MUKo  Ws,          W&   V'       d   W,          W+&   V^,          pV^,          pV^,          pV^ 8X  d   MV^,          p^ pW8  g   K   S'       g   K  V^ 8  g   K  V^ 8  g   K  V^,          pV\        8  g   V\        8  Ed=   W^8  ,          pS! W,          WsW4,           V4      pVV,          pTpV^ 8  d0   S! WVWxVV4       VV,          pVV,          pVV,          pV^ 8X  d   MW,          W&   V'       d   W,          W+&   V^,          pV^,          pV^,          pV^ 8X  d   MS! Ws,          WWV,           V4      pVV,          pTpV^ 8  d0   S! WVWVV4       VV,          pVV,          pVV,          pV^ 8X  d   MBWs,          W&   V'       d   W,          W+&   V^,          pV^,          pV^,          pV^ 8X  g   EKR   V^,          pEKZ  V^ 8X  d   S! WVWxVV4       MV^ 8X  g   Q hW8X  g   Q hS! W4      # )a  
Merge the na elements starting at ssa with the nb elements starting at
ssb = ssa + na in a stable way, in-place.  na and nb must be > 0,
and should have na <= nb. See listsort.txt for more info.

An updated MergeState is returned (with possibly a different min_gallop
or larger temp arrays).

NOTE: compared to CPython's timsort, the requirement that
    "Must also have that keys[ssa + na - 1] belongs at the end of the merge"

is removed. This makes the code a bit simpler and easier to reason about.
r   r   r'   r   )r(   r   r   ssanassbnba_keysa_valuesb_keysb_valuesdestrD   r'   acountbcountrN   	DO_GALLOPr;   rZ   r]   r   r6   r2   rl   s   &&&&&&&          r   merge_lo#make_timsort_impl.<locals>.merge_lo  s,    Av"q&RX--Bh"!rww		1S	 99 2]]
 1fa FFfk6;//!'DJ"'/}AID1HC!GBQwaKFF+ , "(DJ"'/}AID1HC!GBQwaKFF+ yR!VQa

*f
.B q.0J %V[&sxMAHAF1u&tT'-'(* 	qa7!!'DJ"'/}AID1HC!GBQw $FKchLAHAF1u 'tT'-'(* 	qa7!!'DJ"'/}AID1HC!GBQw a
 74!S 7N7;; #222r   c           	       <	 V^ 8  d   V^ 8  d   WF8  g   Q hWSV,           8X  g   Q hS! W4      p S! V P                   V P                  ^ WVV4       TpTpV P                   p	V P                  p
WV,           ^,
          pV^,
          pW4,           ^,
          pS! W4      pV P                  pV^ 8  Ed   V^ 8  Edw   ^ p^ p S! W,          Ws,          4      '       dT   Ws,          W&   V'       d   W,          W+&   V^,          pV^,          pV^,          pV^ 8X  d   MgV^,          p^ pW8  d   MUKo  W,          W&   V'       d   W,          W+&   V^,          pV^,          pV^,          pV^ 8X  d   MV^,          p^ pW8  g   K   S'       g   K  V^ 8  g   K  V^ 8  g   K  V^,          pV\        8  g   V\        8  Edi   W^8  ,          pS! W,          WsV,
          ^,           V^,           V4      pV^,           V,
          pTpV^ 8  d0   S! WVWxVV4       VV,          pVV,          pVV,          pV^ 8X  d   MW,          W&   V'       d   W,          W+&   V^,          pV^,          pV^,          pV^ 8X  d   MS! Ws,          WV,
          ^,           V^,           V4      pV^,           V,
          pTpV^ 8  d0   S! WVWVV4       VV,          pVV,          pVV,          pV^ 8X  d   MBWs,          W&   V'       d   W,          W+&   V^,          pV^,          pV^,          pV^ 8X  g   EK~   V^,          pEK  V^ 8X  d(   S! WW,
          ^,           WWV,
          ^,           V4       MV^ 8X  g   Q hW8X  g   Q hS! W4      # )a  
Merge the na elements starting at ssa with the nb elements starting at
ssb = ssa + na in a stable way, in-place.  na and nb must be > 0,
and should have na >= nb.  See listsort.txt for more info.

An updated MergeState is returned (with possibly a different min_gallop
or larger temp arrays).

NOTE: compared to CPython's timsort, the requirement that
    "Must also have that keys[ssa + na - 1] belongs at the end of the merge"

is removed. This makes the code a bit simpler and easier to reason about.
rs   )r(   r   r   rt   ru   rv   rw   rx   ry   rz   r{   r|   rD   r'   r}   r~   rN   r   r;   rZ   r]   r   r6   r2   rl   rp   s   &&&&&&&          r   merge_hi#make_timsort_impl.<locals>.merge_hiY  sk    Av"q&RX--Bh"!rww		1S	 99 x!|1fhl 2]]
1fa FFfk6;//!'DJ"'/}AID1HC!GBQwaKFF+ , "(DJ"'/}AID1HC!GBQwaKFF+ yR!VQa

*f
.B q.0J %V[&(Q,aQTUAa!AF1u ,D$,2c,-/ 	qa7!!'DJ"'/}AID1HC!GBQw $FKrAsQwPSTAa!AF1u+D$,2c,-/ 	qa7!!'DJ"'/}AID1HC!GBQw a
 74Q!SX\ 7N7;; #222r   c           	       < V P                   pV^8  g   Q hV^ 8  g   Q hW4^,
          8X  g   W4^,
          8X  g   Q hV P                  V,          w  rVV P                  V^,           ,          w  rxV^ 8  d   V^ 8  g   Q hWV,           V8X  g   Q h\        WVV,           4      V P                  V&   W4^,
          8X  d/   V P                  V^,           ,          V P                  V^,           &   S! V 4      p S! W,          WWV,           V4      p	WiV,
          ,          pT	pV^ 8X  d   V # S
! WV,           ^,
          ,          WWx,           Wx,           ^,
          4      p	W,
          pWh8:  d   S! WW%WgV4      # S! WW%WgV4      # )zT
Merge the two runs at stack indices i and i+1.

An updated MergeState is returned.
)r&   r   r   )r(   r   r   rk   r&   rt   ru   rv   rw   rN   rZ   r]   r   r   r-   s   &&&&      r   merge_at#make_timsort_impl.<locals>.merge_at  sO    DDAvvAvvEzQa%Z''**Q-**QU#Av"q&  x3
 !2g.

1A: "

1q5 1BJJq1ur] Dsx=
#g7I 2X\*DsxANW 8Bf2B??Bf2B??r   c                  < V P                   ^8  EdM   V P                  pV P                   ^,
          pV^ 8  dM   W4^,
          ,          P                  W4,          P                  W4^,           ,          P                  ,           8:  gT   V^8  d   W4^,
          ,          P                  W4^,
          ,          P                  W4,          P                  ,           8:  dK   W4^,
          ,          P                  W4^,           ,          P                  8  d
   V^,          pS! WW$4      p EK!  W4,          P                  W4^,           ,          P                  8  d   S! WW$4      p EK[   V # V # )z
Examine the stack of runs waiting to be merged, merging adjacent runs
until the stack invariants are re-established:

1. len[-3] > len[-2] + len[-1]
2. len[-2] > len[-1]

An updated MergeState is returned.

See listsort.txt for more info.
r&   r   sizer(   r   r   r   r&   r   s   &&&  r   merge_collapse)make_timsort_impl.<locals>.merge_collapse'  s     ddQhjjGqAQ7Q3<,,
'A#,BSBS0SSQ7Q3<,,!0A0AGJOO0SSq5>&&Q)<)<<FAb27q5>#6#66b2	r	r   c                  < V P                   ^8  dp   V P                  pV P                   ^,
          pV^ 8  d?   W4^,
          ,          P                  W4^,           ,          P                  8  d
   V^,          pS! WW$4      p K  V # )z
Regardless of invariants, merge all runs on the stack until only one
remains.  This is used at the end of the mergesort.

An updated MergeState is returned.
r   r   s   &&&  r   merge_force_collapse/make_timsort_impl.<locals>.merge_force_collapseC  sg     ddQhjjGqA1uq5>&&Q)<)<<FA"F.B	r   c                  < TpV^,
          pWE8  d*   W,          W,          uW&   W&   V^,          pV^,          pK/  S! W4      '       d=   TpV^,
          pWE8  d*   W,          W,          uW&   W&   V^,          pV^,          pK/  R# R# )z
Reverse a slice, in-place.
Nr   )r   r   rC   rT   rk   jr   s   &&&&  r   reverse_slice(make_timsort_impl.<locals>.reverse_sliceV  s    
 1He#wDGTWFAFAd##AqA%'-y&)$	69QQ  $r   c                  < \        V4      pV^8  d   R# S! V4      pSpV^ 8  d   S
! WWS,           4      w  rgV'       d   S! WWUV,           4       Wd8  d%   \        WC4      pS	! WWUV,           WV,           4       TpS! V \        WV4      4      p S! WV4      p WV,          pW6,          pK  S! WV4      p V P                  ^8X  g   Q hV P                  ^ ,          ^ \        V4      38X  g   Q hR# )z"
Run timsort with the mergestate.
N)r   r   r   r&   r   )r(   r   r   
nremainingminrunrA   r&   descforcerJ   rO   r*   r   r`   r   r   r   s   &&&      r   run_timsort_with_mergestate6make_timsort_impl.<locals>.run_timsort_with_mergestatej  s    
 Y
> &j11n"/:GAdBQ7zF/4%Z@b(2/2B&1BGBOJ ""F3ttqyyzz!}CI...r   c                *   < T pS! S! V 4      W4       R# )z"
Run timsort over the given keys.
Nr   )r   r   r    r   s   & r   run_timsort&make_timsort_impl.<locals>.run_timsort  s    
 #Jt$4dCr   c                &   < S! S! W4      W4       R# )z-
Run timsort over the given keys and values.
Nr   )r   r   r#   r   s   &&r   run_timsort_with_values2make_timsort_impl.<locals>.run_timsort_with_values  s    
 	$$:4$H$(	2r   )r   r   r   )wrapr   r   r   r   r;   rJ   rO   rZ   r]   r   r   r6   r*   r   r   r`   r   r2   r   r    r#   r   r-   r   r   rl   rp   r   s   &f  @@@@@@@@@@@@@@@@@@@@@@@@@r   make_timsort_implr   9   ss   .)N::D7D	" 
" 
S 
S 
S 
S 
P 
P 
S 
S 
S 
S& 
R 
R 
 
 
. 
.b 
!" 
!"H 
R 
Rj 
H 
HV 
 
( 
H 
H 
H 
H  I	W3 W3 
W3t 
Z3 Z3 
Z3z 
,@ ,@ 
,@^ 
 
6 
 
$ 
 
& 
!/ !/ 
!/H 
D 
D 
2 
2 !:{LL)h(n. .r   c                      \        R  .V O5!  # )c                     V # r
   r   )fs   &r   <lambda>!make_py_timsort.<locals>.<lambda>  s    r   )r   )argss   *r   make_py_timsortr     s    k2T22r   c                  2   a ^ RI Ho \        V3R l.V O5!  # )r   )jitc                 "   < S! R R7      ! V 4      # )T)nopythonr   )r   r   s   &r   r   "make_jit_timsort.<locals>.<lambda>  s    T(:1(=r   )numbar   r   )r   r   s   *@r   make_jit_timsortr     s    = %#% %r   )compilerO   rJ   rZ   r]   r    r*   r-   r`   r   r   r   r   r   r   r   )r'   r   r   r   r&   )rC   r   )__doc__collections
numba.corer   
namedtupler   r   r   r   r   r   r   r   r   r   r   r   <module>r      s      $..	 *   
   ##BD
 !!*.?@m.`3%r   