
    -i"                     j   d dl Z d dlZd dlZd dlZd dlmZmZ 	 d dlmZ n# e	$ r	 d dl
mZ Y nw xY wd dlZ G d de          Z G d de          Z G d d	e          Z G d
 de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d d          ZdS )    N)
IU_StorageDummyStorage)__version__c                       e Zd ZdS )IndexExceptionN__name__
__module____qualname__     P/var/www/html/speakWrite/venv/lib/python3.11/site-packages/codernitydb3/index.pyr   r   #           Dr   r   c                       e Zd ZdS )IndexNotFoundExceptionNr   r   r   r   r   r   '   r   r   r   c                       e Zd ZdS )ReindexExceptionNr   r   r   r   r   r   +   r   r   r   c                       e Zd ZdS )TryReindexExceptionNr   r   r   r   r   r   /   r   r   r   c                       e Zd ZdS )ElemNotFoundNr   r   r   r   r   r   3   r   r   r   c                       e Zd ZdS )DocIdNotFoundNr   r   r   r   r   r   7   r   r   r   c                       e Zd ZdS )IndexConflictNr   r   r   r   r   r   ;   r   r   r   c                       e Zd ZdS )IndexPreconditionsExceptionNr   r   r   r   r   r   ?   r   r   r   c                       e Zd ZeZdZdZdZdZd Zd Z	d Z
d Zd	 Zd
 Zi fdZd Zd Zd Zd Zd Zd Zd Zd dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z dS )!Index   o   u   d c                 0    || _         d| _        || _        d S )Ni  )name
_start_inddb_path)selfr'   r%   s      r   __init__zIndex.__init__M   s    	r   c                    t           j                            t           j                            | j        | j        dz                       st          d          t          j        t           j                            | j        | j        dz             dd          | _	        | 
                                 |                                  d S )N_buckzDoesn't existszr+br   )	buffering)ospathisfilejoinr'   r%   r   ioopenbuckets_fix_params_open_storager(   s    r   
open_indexzIndex.open_indexS   s    w~~bgll4<W9LMMNN 	3 !1222wrw||DL$)g:MNN$)*, , , 	r   c                 j    | j                                          | j                                         d S N)r3   closestorager6   s    r   _closezIndex._close\   s0    r   c                 ~    |                                   |                                  |                                  d S r9   )flushfsyncr<   r6   s    r   close_indexzIndex.close_index`   s-    



r   c                     t                      r9   NotImplementedErrorr6   s    r   create_indexzIndex.create_indexe       !###r   c                    | j                             d           t          j        | j                             | j                            }|                                D ]\  }}|| j        |<   | j                             dd           d S )Nr      )r3   seekmarshalloadsreadr&   items__dict__)r(   propskvs       r   r4   zIndex._fix_paramsh   s    !dl//@@AAKKMM 	! 	!DAq DM!!Qr   c                 6   | j                             d           t          j        | j                             | j                            }|                    |           | j                             d           t          j        |          }t          |          | j        k    rt          d          | j         
                    |           |                                  | j                             dd           | j                            |           d S )Nr   zTo big propsrG   )r3   rH   rI   rJ   rK   r&   updatedumpslenr   writer>   rM   )r(   	in_paramsrN   datas       r   _save_paramszIndex._save_paramso   s    !dl//@@AAY!}U##t99t&& 0004   

!QU#####r   c                     d S r9   r   r(   argskwargss      r   r5   zIndex._open_storage|       r   c                     d S r9   r   rZ   s      r   _create_storagezIndex._create_storage   r]   r   c                 8    | j                                          d S r9   )r;   destroyrZ   s      r   _destroy_storagezIndex._destroy_storage   s    r   c                     t                      r9   rB   r(   keys     r   	_find_keyzIndex._find_key   rE   r   c                     t                      r9   rB   r(   doc_idre   startsizes        r   rR   zIndex.update   rE   r   c                     t                      r9   rB   rh   s        r   insertzIndex.insert   rE   r   c                     t                      r9   rB   rd   s     r   getz	Index.get   rE   r   Nr   c                     t                      r9   rB   )r(   re   
start_fromlimits       r   get_manyzIndex.get_many   rE   r   c                     t                      r9   rB   )r(   	start_poss     r   allz	Index.all   rE   r   c                     t                      r9   rB   )r(   re   rj   rk   s       r   deletezIndex.delete   rE   r   c                     t                      r9   rB   r(   rW   s     r   make_key_valuezIndex.make_key_value   rE   r   c                     t                      r9   rB   rz   s     r   make_keyzIndex.make_key   rE   r   c                     t                      r9   rB   rZ   s      r   compactzIndex.compact   rE   r   c                 
   |                                   t          j                            | j        | j        dz             }t          j        |           |                                  | j        	                                 d S )Nr+   )
r<   r-   r.   r0   r'   r%   unlinkrb   rf   clear)r(   r[   r\   bucket_files       r   ra   zIndex.destroy   si    gll4<W1DEE
	+r   c                 |    	 | j                                          | j                                         d S #  Y d S xY wr9   )r3   r>   r;   r6   s    r   r>   zIndex.flush   sE    	L   L     	DDs   26 ;c                     	 t          j        | j                                                   | j                                         d S #  Y d S xY wr9   )r-   r?   r3   filenor;   r6   s    r   r?   zIndex.fsync   sO    	HT\((**+++L     	DDs   AA Ac                 z    |r| j                             |          \  }}nd}d}|                     ||||          S N   r   )r;   rm   rR   r(   ri   re   valuerj   rk   s         r   update_with_storagezIndex.update_with_storage   G     	,--e44KE44ED{{63t444r   c                 z    |r| j                             |          \  }}nd}d}|                     ||||          S r   )r;   rm   r   s         r   insert_with_storagezIndex.insert_with_storage   r   r   )Nr   )!r	   r
   r   r   STATUS_OSTATUS_USTATUS_Dcustom_headerr)   r7   r<   r@   rD   r4   rX   r5   r_   rb   rf   rR   rm   ro   rs   rv   rx   r{   r}   r   ra   r>   r?   r   r   r   r   r   r   r   C   s       KHHHM        
$ $ $      &( $ $ $ $      $ $ $$ $ $$ $ $$ $ $$ $ $ $$ $ $$ $ $$ $ $$ $ $$ $ $      5 5 55 5 5 5 5r   r   )r-   rI   structshutilcodernitydb3.storager   r   codernitydb3r   ImportErrorr)   r1   	Exceptionr   r   r   r   r   r   r   r   r   r   r   r   <module>r      s(  & 
			    9 9 9 9 9 9 9 9%((((((( % % %$$$$$$$$% 
				 	 	 	 	Y 	 	 		 	 	 	 	^ 	 	 		 	 	 	 	~ 	 	 		 	 	 	 	* 	 	 		 	 	 	 	> 	 	 		 	 	 	 	L 	 	 		 	 	 	 	N 	 	 		 	 	 	 	. 	 	 	C5 C5 C5 C5 C5 C5 C5 C5 C5 C5s   ! //