
    _jk                         d dl Z d dlZd dl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  G d de          Z G d	 d
e          Z G d de          ZdS )    N)AnyCallable)Segment)override)DictOptional)ABCabstractmethodc                       e Zd Zedej        dee         fd            Zedej        dee         fd            Z	edej        deddfd            Z
ed	d            ZdS )
SegmentCachekeyreturnc                     d S N selfr   s     f/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/chromadb/segment/impl/manager/cache/cache.pygetzSegmentCache.get           c                     d S r   r   r   s     r   popzSegmentCache.pop   r   r   valueNc                     d S r   r   r   r   r   s      r   setzSegmentCache.set   r   r   c                     d S r   r   r   s    r   resetzSegmentCache.reset   r   r   r   N)__name__
__module____qualname__r
   uuidUUIDr   r   r   r   r   r    r   r   r   r   r   
   s        ty Xg%6    ^ ty Xg%6    ^ ty  T    ^    ^  r   r   c                       e Zd Zd Zedej        dee         fd            Z	edej        dee         fd            Z
edej        deddfd            Zed
d	            ZdS )
BasicCachec                 D    i | _         t          j                    | _        d S r   )cache	threadingRLocklockr   s    r   __init__zBasicCache.__init__   s    /1
O%%			r   r   r   c                 x    | j         5  | j                            |          cd d d            S # 1 swxY w Y   d S r   )r-   r*   r   r   s     r   r   zBasicCache.get!   s    Y 	' 	':>>#&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	's   /33c                 z    | j         5  | j                            |d           cd d d            S # 1 swxY w Y   d S r   )r-   r*   r   r   s     r   r   zBasicCache.pop&   s    Y 	- 	-:>>#t,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s   044r   Nc                 Z    | j         5  || j        |<   d d d            d S # 1 swxY w Y   d S r   r-   r*   r   s      r   r   zBasicCache.set+   sy    Y 	$ 	$#DJsO	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$s    $$c                 T    | j         5  i | _        d d d            d S # 1 swxY w Y   d S r   r2   r   s    r   r    zBasicCache.reset0   su    Y 	 	DJ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   !!r!   )r"   r#   r$   r.   r   r%   r&   r   r   r   r   r   r    r   r   r   r(   r(      s        & & & 'ty 'Xg%6 ' ' ' X' -ty -Xg%6 - - - X- $ty $ $T $ $ $ X$    X  r   r(   c            
       6   e Zd ZdZ	 ddedeej        gef         deeej        e	ge
f                  fdZdej        fdZedej        d	ee	         fd
            Zedej        d	ee	         fd            Zedej        de	d	dfd            Zed             ZdS )SegmentLRUCachezA simple LRU cache implementation that handles objects with dynamic sizes.
    The size of each object is determined by a user-provided size function.Ncapacity	size_funccallbackc                 |    || _         || _        i | _        g | _        || _        t          j                    | _        d S r   )r6   r7   r*   historyr8   r+   r,   r-   )r   r6   r7   r8   s       r   r.   zSegmentLRUCache.__init__:   s:     !"/1
 O%%			r   r   c                     || j         v r6| j                             |           | j                             |           d S | j                             |           d S r   )r:   removeappendr   s     r   _upsert_keyzSegmentLRUCache._upsert_keyG   s]    $,L$$$L$$$$$L$$$$$r   r   c                     | j         5  |                     |           || j        v r| j        |         cd d d            S 	 d d d            d S # 1 swxY w Y   d S r   )r-   r>   r*   r   s     r   r   zSegmentLRUCache.getN   s    Y 	 	S!!!dj  z#	 	 	 	 	 	 	 	
 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   +A AAAc                     | j         5  || j        v r| j                            |           | j                            |d           cd d d            S # 1 swxY w Y   d S r   )r-   r:   r<   r*   r   r   s     r   r   zSegmentLRUCache.popW   s    Y 	- 	-dl""##C(((:>>#t,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s   >AAAr   c                      j         5  | j        v r	 d d d            d S                      |          } fd j        D             }t          |                                          }d}||z    j        k    rt           j                  |k    ru j        |         }| j        v r4                     | j        |                     j        |= |||         z  }|dz  }||z    j        k    rt           j                  |k    u| j        |<    	                    |           d d d            d S # 1 swxY w Y   d S )Nc                 <    i | ]}|                     |          S r   )r7   ).0r   r   s     r   
<dictcomp>z'SegmentLRUCache.set.<locals>.<dictcomp>d   s'    HHHcdnnS11HHHr   r      )
r-   r*   r7   sumvaluesr6   lenr:   r8   r>   )r   r   r   	item_size	key_sizes
total_sizeindex
key_deletes   `       r   r   zSegmentLRUCache.set^   s   Y 	" 	"dj  	" 	" 	" 	" 	" 	" 	" 	" s++IHHHHTZHHHIY--//00JEy(4=88S=N=NQV=V=V!\%0
++MM*dj.DEEE
:.)J"77J
 y(4=88S=N=NQV=V=V $DJsOS!!!#	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"s   D3DD33D7:D7c                 b    | j         5  i | _        g | _        d d d            d S # 1 swxY w Y   d S r   )r-   r*   r:   r   s    r   r    zSegmentLRUCache.resets   s|    Y 	 	DJDL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   $((r   )r"   r#   r$   __doc__intr   r%   r&   r   r   r   r.   r>   r   r   r   r   r    r   r   r   r5   r5   6   sY       O O CG	& && TYK,-& 8TY$8#$=>?	& & & &%ty % % % % ty Xg%6    X -ty -Xg%6 - - - X- "ty " "T " " " X"(   X  r   r5   )r+   r%   typingr   r   chromadb.typesr   	overridesr   r   r   abcr	   r
   r   r(   r5   r   r   r   <module>rU      s                        " " " " " "       ! ! ! ! ! ! ! ! # # # # # # # #    3   $       4A A A A Aj A A A A Ar   