+
    &h8/                         R t ^ RIt^ RIHt ^ RIHtHt  ^RIH	t	 ]	! RR7      t
RR.t ! R	 R]4      t]t ! R
 R]4      tR#   ] d    ]! 4       t
 L.i ; i)a  Python's builtin :class:`list` is a very fast and efficient
sequence type, but it could be better for certain access patterns,
such as non-sequential insertion into a large lists. ``listutils``
provides a pure-Python solution to this problem.

For utilities for working with iterables and lists, check out
:mod:`iterutils`. For the a :class:`list`-based version of
:class:`collections.namedtuple`, check out :mod:`namedutils`.
N)log)chainislice)make_sentinel_MISSING)var_nameBList
BarrelListc                      a  ] tR t^<t o RtRt RR lt]R 4       tR t	R t
R tR	 tR
 tR tRR ltRR lt]t]R 4       tR tR tR tR tR tR tR tR tR tR tR tR tR t R t!Rt"V t#R# )r	   aU  The ``BarrelList`` is a :class:`list` subtype backed by many
dynamically-scaled sublists, to provide better scaling and random
insertion/deletion characteristics. It is a subtype of the builtin
:class:`list` and has an identical API, supporting indexing,
slicing, sorting, etc. If application requirements call for
something more performant, consider the `blist module available on
PyPI`_.

The name comes by way of Kurt Rose, who said it reminded him of
barrel shifters. Not sure how, but it's BList-like, so the name
stuck. BList is of course a reference to `B-trees`_.

Args:
    iterable: An optional iterable of initial values for the list.

>>> blist = BList(range(100000))
>>> blist.pop(50000)
50000
>>> len(blist)
99999
>>> len(blist.lists)  # how many underlying lists
8
>>> slice_idx = blist.lists[0][-1]
>>> blist[slice_idx:slice_idx + 2]
BarrelList([11637, 11638])

Slicing is supported and works just fine across list borders,
returning another instance of the BarrelList.

.. _blist module available on PyPI: https://pypi.python.org/pypi/blist
.. _B-trees: https://en.wikipedia.org/wiki/B-tree

i  Nc                L    . .V n         V'       d   V P                  V4       R # R # Nlistsextendselfiterables   &&1lib/python3.14/site-packages/boltons/listutils.py__init__BarrelList.__init__b   s    T
KK!     c           	         \        V 4      V P                  r!\        \        V\	        V^,           ^4      ,          4      4      # )   )len_size_factorintroundmath_log)r   len_selfsize_factors   &  r   _cur_size_limitBarrelList._cur_size_limitg   s3     #D	4+<+<+5x1a'@@ABBr   c                    V^ 8  d   V\        V 4      ,          pYP                  r2\        \        V4      4       F$  p\        W4,          4      pW%8  d    MW%,          pK&  	  V^ 8  d   R# XV3# )    )NN)r   r   range)r   indexrel_idxr   list_idxlen_lists   &&    r   _translate_indexBarrelList._translate_indexl   sj    19SYE

c%j)H5?+H!G	 *
 Q;  r   c                R   V^ 8  d   V\        V P                  4      ,          pV P                  V,          \        V 4      r2V P                  p\        V4      V8  dK   V^,          p\        V4      V8  d0   V^,           pV P                  P                  WbV) R 4       W%) R1 K?  R# R# )r#   NTF)r   r   r    insert)r   r'   cur_listr   
size_limit
half_limitnext_list_idxs   &&     r   _balance_listBarrelList._balance_listy   s    a<DJJ'H!ZZ13t9())
x=:%#qJh-*, (1

!!-:+,1GH[\*r   c                L   \        V P                  4      ^8X  d6   V P                  ^ ,          P                  W4       V P                  ^ 4       R# V P	                  V4      w  r4Vf   \        4       hV P                  V,          P                  WB4       V P                  V4       R# )   N)r   r   r,   r1   r)   
IndexError)r   r%   itemr'   r&   s   &&&  r   r,   BarrelList.insert   s    tzz?aJJqM  -q! 	 !% 5 5e <H l"JJx ''6x(r   c                J    V P                   R,          P                  V4       R# r4   N)r   append)r   r6   s   &&r   r;   BarrelList.append   s    

2d#r   c                J    V P                   R,          P                  V4       R# r9   r   r   s   &&r   r   BarrelList.extend   s    

2h'r   c                   V P                   p\        V4      ^8X  d*   V'       g"   V P                   ^ ,          P                  4       # T;'       d
    V^ ,          pVR8X  g   Ve   VR8X  dI   VR,          P                  4       p\        V4      ^8  d    VR,          '       g   VP                  4        V# V P                  V4      w  rVVf   \	        4       hW%,          P                  V4      pV P                  V4       V# )r4    r:   )r   r   popr)   r5   r1   )r   ar   r%   retr'   r&   s   &*     r   rA   BarrelList.pop   s    

u:?1::a=$$&&

adB;%-5B;)--/C5zA~eBii		 
 !% 5 5e <H l"/%%g.Cx(
r   c                    T pVf   ^ pVf   \        V 4      pVe"   V^ 8  d   V) pV) V) ^,
          r!\        V 4      pV^ 8  d   V\        V 4      ,          pV^ 8  d   V\        V 4      ,          p\        WAW#4      # r   )r   reversedr   )r   startstopstepr   s   &&&& r   
iter_sliceBarrelList.iter_slice   s    =E<t9Dq5D &4%!)4~H19SYE!8CIDht22r   c                ^   Vef   \        V4      ^8  dV   \        V P                  ^ W4      V P                  VR V4      4      pW@P                  ^ ,          R&   V P	                  ^ 4       R # Vf   ^ pVf   \        V 4      pV P                  V4      w  rVV P                  V4      w  rxVf   \        4       hVf   \        4       hWW8X  d   V P                  V,          Wh1 R # WW8  dE   V P                  V^,           V1 V P                  V,          VR 1 V P                  V,          R V1 R # Q R4       h)NNNNzGstart list index should never translate to greater than stop list index)absr   rJ   r   r1   r   r)   r5   )	r   rG   rH   rI   new_liststart_list_idxstart_rel_idxstop_list_idxstop_rel_idxs	   &&&&     r   	del_sliceBarrelList.del_slice   s$   D	AT__Q<!__T4>@H'JJqM!q!=E<t9D(,(=(=e(D%&*&;&;D&A#!, ,*

>*=+EF+

>A-m;<

>*=>:

=)-<-8< ; <5r   c                    V ! V4      # r   r@   )clsits   &&r   from_iterableBarrelList.from_iterable   s    2wr   c                B    \         P                  ! V P                  4      # r   )r   rY   r   r   s   &r   __iter__BarrelList.__iter__   s    ""4::..r   c                b    \         P                  ! R  \        V P                  4       4       4      # )c              3   8   "   T F  p\        V4      x  K  	  R # 5ir   )rF   ).0ls   & r   	<genexpr>*BarrelList.__reversed__.<locals>.<genexpr>   s     "M8L18A;;8Ls   )r   rY   rF   r   r\   s   &r   __reversed__BarrelList.__reversed__   s"    """M8L"MMMr   c                h    \        V P                   Uu. uF  p\        V4      NK  	  up4      # u upi r   )sumr   r   )r   rb   s   & r   __len__BarrelList.__len__   s'    DJJ/JqCFJ/00/s   /c                >    V P                    F  pW9   g   K   R # 	  R# )TFr   r   r6   curs   && r   __contains__BarrelList.__contains__   s    ::C{  r   c                X    VP                   VP                  VP                  rCpV P                  W#V4      pV P	                  V4      pV#   \
         d    \        P                  ! T4      p Mi ; iT P                  T4      w  rxTf   \        4       hT P                  T,          T,          # r   )rG   rH   rI   rJ   rY   AttributeErroroperatorr%   r)   r5   r   )	r   r%   rG   rH   rI   rJ   rC   r'   r&   s	   &&       r   __getitem__BarrelList.__getitem__   s    	 %UZZE d;J$$Z0CJ  	*NN5)E	* !11%8,zz(#G,,s   #A
 
!A.-A.c                .    VP                   VP                  VP                  rCpV P                  W#V4       R #   \         d    \
        P                  ! T4      p Mi ; iT P                  T4      w  rVTf   \        4       hT P                  T,          T R # r   )
rG   rH   rI   rT   rr   rs   r%   r)   r5   r   )r   r%   rG   rH   rI   r'   r&   s   &&     r   __delitem__BarrelList.__delitem__   s    	 %UZZE NN5-	  	*NN5)E	*
 !11%8,JJx )s   #9 !AAc                    VP                   VP                  VP                  rTp\        V P                  4      ^8X  d   W P                  ^ ,          V&   M\        V 4      pW&V&   V.V P                  R&   V P                  ^ 4       R#   \         d    \        P                  ! T4      p Mi ; iT P                  T4      w  rxTf   \        4       hY P                  T,          T&   R# r4   rM   N)rG   rH   rI   r   r   listr1   rr   rs   r%   r)   r5   )	r   r%   r6   rG   rH   rI   tmpr'   r&   s	   &&&      r   __setitem__BarrelList.__setitem__	  s    	 %UZZE 4::!#'+

1e$4j!E
!$

1q!  	*NN5)E	* !11%8,(,

8W%s   #B !B+*B+c                H    V P                  W^4      pV P                  V4      # )r4   )rJ   rY   )r   rG   rH   rJ   s   &&& r   __getslice__BarrelList.__getslice__  s#    __U!4
!!*--r   c                    \        V P                  4      ^8X  d   W0P                  ^ ,          W% M\        V 4      pW4W% V.V P                  R&   V P                  ^ 4       R# rz   )r   r   r{   r1   )r   rG   rH   sequencer|   s   &&&& r   __setslice__BarrelList.__setslice__   sR    tzz?a(0JJqM%%t*C&O EDJJqM1r   c                N    V P                   P                   R \        V 4      : R2# )())	__class____name__r{   r\   s   &r   __repr__BarrelList.__repr__*  s$    ..))*!DJ>;;r   c                p   \        V P                  4      ^8X  d$   V P                  ^ ,          P                  4        R# V P                   F  pVP                  4        K  	  \        \        P
                  ! V P                  4      4      pV P                  R W P                  ^ &   V P                  ^ 4       R# rz   )r   r   sortsortedr   rY   r1   )r   li
tmp_sorteds   &  r   r   BarrelList.sort-  s|     tzz?aJJqM jj	 ! 3 3DJJ ?@J

1&JJqMq!r   c                    V P                    F  pVP                  4        K  	  V P                   P                  4        R # r   )r   reverse)r   rn   s   & r   r   BarrelList.reverse:  s)    ::CKKM 

r   c                r    \        V P                   Uu. uF  q"P                  V4      NK  	  up4      # u upi r   )rh   r   countrm   s   && r   r   BarrelList.count?  s)    tzz:zIIdOz:;;:s   4c                    ^ pV P                    F  p VP                  V4      pW$,           u # 	  \        V: R24      h  \         d    T\        T4      ,          p KP  i ; i)r#   z is not in list)r   r%   
ValueErrorr   )r   r6   	len_accumrn   r&   s   &&   r   r%   BarrelList.indexB  sc    	::C&))D/ **  D8?344  &SX%	&s   ?A A rl   r   )$r   
__module____qualname____firstlineno____doc__r   r   propertyr    r)   r1   r,   r;   r   rA   rJ   rT   __delslice__classmethodrY   r]   re   ri   ro   rt   rw   r}   r   r   r   r   r   r   r%   __static_attributes____classdictcell____classdict__s   @r   r	   r	   <   s      D LO"
 C C!
$("3&<8 L /N1-*-&.<"
<5 5r   c                   4   a  ] tR tRt o RtRR ltR tRtV tR# )	SplayListiP  zLike a `splay tree`_, the SplayList facilitates moving higher
utility items closer to the front of the list for faster access.

.. _splay tree: https://en.wikipedia.org/wiki/Splay_tree
c                Z    W8X  d   R # V P                  V4      pV P                  W#4       R # r   )rA   r,   )r   
item_index
dest_indexr6   s   &&& r   shiftSplayList.shiftW  s%    #xx
#J%r   c                0    W,          W,          uW&   W&   R # r   r@   )r   r   r   s   &&&r   swapSplayList.swap]  s    -1-=t?O*$*r   r@   N)r#   )	r   r   r   r   r   r   r   r   r   r   s   @r   r   r   P  s     &P Pr   r   )r   rs   mathr   r   	itertoolsr   r   	typeutilsr   r   ImportErrorobject__all__r{   r	   r   r   r@   r   r   <module>r      sp   >    #(j1H
 L
!N5 N5b 	P P  xHs   A AA