
    yf                     N    S SK Jr   " S S\5      r " S S5      r " S S5      rg)	   )Errorc                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )
StableDict   z,A dict subclass with stable items() orderingc                 2   > [        [        TU ]	  5       5      $ N)sortedsuperitems)self	__class__s    9/usr/lib/python3/dist-packages/borg/helpers/datastruct.pyr   StableDict.items   s    egmo&&     )__name__
__module____qualname____firstlineno____doc__r   __static_attributes____classcell__)r   s   @r   r   r      s    6' 'r   r   c                   T    \ rS rSrSr " S S\\5      rSS jrS r	SS jr
SS	 jrS
rg)Buffer
   z'
Provides a managed, resizable buffer.
c                       \ rS rSrSrSrg)Buffer.MemoryLimitExceeded   z2Requested buffer size {} is above the limit of {}.r   Nr   r   r   r   r   r   r   r   r   MemoryLimitExceededr      s    @r   r    Nc                     [        U5      (       d   S5       eUb  X#::  d   S5       eXl        X0l        U R                  USS9  g)z~
Initialize the buffer: use allocator(size) call to allocate a buffer.
Optionally, set the upper <limit> for the buffer size.
z-must give alloc(size) function as first paramNzinitial size must be <= limitT)init)callable	allocatorlimitresize)r   r$   sizer%   s       r   __init__Buffer.__init__   sJ    
 	""S$SS"}N/NN-"
Dt$r   c                 ,    [        U R                  5      $ r   )lenbufferr   s    r   __len__Buffer.__len__   s    4;;r   c                     [        U5      nU R                  b.  XR                  :  a  [        R                  XR                  5      eU(       d  [	        U 5      U:  a  U R                  U5      U l        gg)a  
resize the buffer - to avoid frequent reallocation, we usually always grow (if needed).
giving init=True it is possible to first-time initialize or shrink the buffer.
if a buffer size beyond the limit is requested, raise Buffer.MemoryLimitExceeded (OSError).
N)intr%   r   r    r+   r$   r,   r   r'   r"   s      r   r&   Buffer.resize    sX     4y::!dZZ&7,,T::>>3t9t#...DK $r   c                 B    Ub  U R                  X5        U R                  $ )z
return a buffer of at least the requested size (None: any current size).
init=True can be given to trigger shrinking of the buffer to the given size.
)r&   r,   r2   s      r   get
Buffer.get,   s     
 KK#{{r   )r$   r,   r%   )i   N)F)NF)r   r   r   r   r   r   OSErrorr    r(   r.   r&   r5   r   r   r   r   r   r   
   s+    AeW A	% 
/r   r   c                   R    \ rS rSrSr " S S\5      rS rS rS r	S r
S	 rS
 rSrg)EfficientCollectionQueue6   zD
An efficient FIFO queue that splits received elements into chunks.
c                       \ rS rSrSrSrg)&EfficientCollectionQueue.SizeUnderflow;   zHCould not pop_front first {} elements, collection only has {} elements..r   Nr   r   r   r   SizeUnderflowr<   ;   s    Vr   r>   c                 8    / U l         SU l        Xl        X l        g)z
Initializes empty queue.
Requires split_size to define maximum chunk size.
Requires member_type to be type defining what base collection looks like.
    N)buffersr'   
split_sizemember_type)r   rB   rC   s      r   r(   !EfficientCollectionQueue.__init__>   s     	$&r   c                 f    U R                   (       d  U R                  5       $ U R                   S   nU$ )z
Returns first chunk from queue without removing it.
Returned collection will have between 1 and split_size length.
Returns empty collection when nothing is queued.
r@   )rA   rC   )r   r,   s     r   
peek_front#EfficientCollectionQueue.peek_frontI   s,     ||##%%ar   c                 F   XR                   :  a  [        R                  XR                   5      eUS:  am  U R                  S   n[	        U[        U5      5      nX#S nU(       a  X R                  S'   OU R                  S	 X-  nU =R                   U-  sl         US:  a  Ml  gg)zf
Removes first size elements from queue.
Throws if requested removal size is larger than whole queue.
r@   N)r'   r9   r>   rA   minr+   )r   r'   r,   	to_removes       r   	pop_front"EfficientCollectionQueue.pop_frontT   s    
 ))*88yyIIQh\\!_FD#f+.IJ'F"(QLLODII"I Qhr   c                    U R                   (       d  U R                  5       /U l         U(       a  U R                   S   n[        U5      U R                  :  a+  U R                  5       nU R                   R	                  U5        [        [        U5      U R                  [        U5      -
  5      nX!SU -  nXS nX R                   S'   U =R                  U-  sl        U(       a  M  gg)zU
Adds data at end of queue.
Takes care to chunk data into split_size sized elements.
N)rA   rC   r+   rB   appendrI   r'   )r   datar,   to_adds       r   	push_back"EfficientCollectionQueue.push_backf   s    
 || ,,./DL\\"%F6{doo-))+##F+TDOOc&k$ABF7Fm#F=D%LLIII dr   c                     U R                   $ )z6
Current queue length for all elements in all chunks.
r'   r-   s    r   r.    EfficientCollectionQueue.__len__y   s     yyr   c                      U R                   S:g  $ )z$
Returns true if queue isn't empty.
r@   rU   r-   s    r   __bool__!EfficientCollectionQueue.__bool__   s     yyA~r   )rA   rC   r'   rB   N)r   r   r   r   r   r   r>   r(   rF   rK   rR   r.   rX   r   r   r   r   r9   r9   6   s3    W W	'	#$ &r   r9   N)errorsr   dictr   r   r9   r   r   r   <module>r\      s+    ' ') )XM Mr   