
    -i~                        d dl Z d dlZd dlZd dlZd dlZd dlmZmZmZm	Z	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  ej        d          rd dlmZ  ej        ed                    	 d d	lmZ n# e$ r	 d d	lmZ Y nw xY w 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"dS )    N)IndexIndexExceptionDocIdNotFoundElemNotFoundTryReindexExceptionIndexPreconditionsException)	cache1lvl)random_hex_32)
IU_StorageDummyStorage)cdb_environment	rlock_obj)patch)__version__c                        e Zd ZdZ	 	 	 	 d" fd	Z fdZd Zd	 Z fd
Zd Z	d Z
d Zd#dZd Zd Zd Zd Zd$dZd%dZd Zd#dZd&dZd Zd'dZd%dZd Zd Zd  Z fd!Z xZS )(IU_HashIndexz
    That class is for Internal Use only, if you want to use HashIndex just subclass the :py:class:`HashIndex` instead this one.

    That design is because main index logic should be always in database not in custom user indexes.
    <32s{key}IIcI Ncc                    |rd|v r|                     d|          }t          t          |                               ||           || _        |st
          }|rt          |t                    s|j        }|| _	        d| _
        d| _        t          j        | j                  | _        || _        t          j        | j                  | _        t#          d          } || j                  | _         || j                  | _        t          j        | j                  | _        t          j        | j                  | _        | j        dz   | j        z  | j        z   dz   | _        dS )a{  
        The index is capable to solve conflicts by `Separate chaining`
        :param db_path: database path
        :type db_path: string
        :param name: index name
        :type name: ascii string
        :param line_format: line format, `key_format` parameter value will replace `{key}` if present.
        :type line_format: string (32s{key}IIcI by default) {doc_id}{hash_key}{start}{size}{status}{next}
        :param hash_lim: maximum hash functon results (remember about birthday problem) count from 0
        :type hash_lim: integer
        :param storage_class: Storage class by default it will open standard :py:class:`codernitydb3.storage.Storage` (if string has to be accesible by globals()[storage_class])
        :type storage_class: class name which will be instance of codernitydb3.storage.Storage instance or None
        :param key_format: a index key format
        z{key}Nz<Id         )replacesuperr   __init__hash_limr   
isinstancestr__name__storage_classstoragebucket_line_formatstructcalcsizebucket_line_sizeentry_line_formatentry_line_sizer	   	_find_key_locate_doc_idStructbucket_structentry_struct
_start_ind
data_start)	selfdb_pathnamer'   r   r!   
key_formatcache	__class__s	           U/var/www/html/speakWrite/venv/lib/python3.11/site-packages/codernitydb3/hash_index.pyr   zIU_HashIndex.__init__2   s^   *  	O'%666 1 9 9': N NlD!!**7D999  	'&M 	3M3!?!? 	3)2M*"& &0G H H!2%t/EFF#t~..#eD$788#]4+BCC"M$*@AA= $ 568<HJKL    c                    t          t          |                                            t          j        | j                  | _        t          j        | j                  | _        t          j	        | j                  | _
        t          j	        | j                  | _        | j        dz   | j        z  | j        z   dz   | _        d S )Nr   r   )r   r   _fix_paramsr$   r%   r#   r&   r'   r(   r+   r,   r-   r   r.   r/   r0   r5   s    r6   r9   zIU_HashIndex._fix_params_   s    lD!!--/// &0G H H%t/EFF#]4+BCC"M$*@AA= $ 568<HJKLr7   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 existsr+br   	buffering)ospathisfilejoinr1   r2   r   ioopenbucketsr9   _open_storager0   s    r6   
open_indexzIU_HashIndex.open_indexh   s    w~~bgll4<W9LMMNN 	3 !1222wrw||DL$)g:MNN$)*, , , 	r7   c           	         t           j                            t           j                            | j        | j        dz                       rt          d          t          j        t           j                            | j        | j        dz             d          5 }t          | j        | j
        | j        | j        | j        | j                  }|                    t!          j        |                     d d d            n# 1 swxY w Y   t          j        t           j                            | j        | j        dz             dd          | _        |                                  d S )Nr<   zAlready existszw+b)r2   r#   r'   r   r   r!   r=   r   r>   )r@   rA   rB   rC   r1   r2   r   rD   rE   dictr#   r'   r   r   r!   writemarshaldumpsrF   _create_storage)r0   fpropss      r6   create_indexzIU_HashIndex.create_indexq   sk   7>>"',,t|TY5HIIJJ 	3 !1222WRW\\$,	G0CDD  	* di,0,C+/+A"&-%)%5'+'9; ; ;E GGGM%(()))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* wrw||DL$)g:MNN$)*, , , 	s   ADDDc                 ~    t          t          |                                            |                                  d S N)r   r   destroy_clear_cacher:   s    r6   rU   zIU_HashIndex.destroy   s7    lD!!))+++r7   c                     t                      | j                 }| j        s || j        | j                  | _        | j                                         d S rT   )globalsr!   r"   r1   r2   rE   r0   ss     r6   rG   zIU_HashIndex._open_storage   sN    IId()| 	61T\4955DLr7   c                     t                      | j                 }| j        s || j        | j                  | _        | j                                         d S rT   )rX   r!   r"   r1   r2   createrY   s     r6   rO   zIU_HashIndex._create_storage   sN    IId()| 	61T\4955DLr7   c                    |                      |          }| j                            |           | j                            | j                  }|r| j                            |          d         }|sdddd| j        fS |                     ||          \  }}}}}	}
}|
| j	        k    r,	 |                     ||          \  }}}}}	}
}|
| j	        k    rn+||||	|
fS dddd| j        fS zL
        Find the key position

        :param key: the key to find
        r   N)
_calculate_positionrF   seekreadr&   r,   unpackSTATUS_U_locate_keySTATUS_D)r0   keystart_position	curr_datalocationfound_atdoc_idl_keystartsizestatus_nexts               r6   r)   zIU_HashIndex._find_key   s&    11#66.)))L%%d&;<<	 	3)00;;A>H 7T1a66BFBRBRXC C?HfeUD&%&&JNJZJZUK$ K$GHfeUD&%..	
 5%v55q!T]22r7   r   r   c              #   B  K   d }|                      |          }| j                            |           | j                            | j                  }|r | j                            |          d         }|rM|snJ	 |                     ||          \  }}}	}
}}}|| j        k    r|	|k    r|dz  }|}n# t          $ r Y nw xY w|M|rY|sd S 	 |                     ||          \  }}}	}
}}}|| j        k    r|	|k    r||
||fV  |dz  }|}n# t          $ r Y d S w xY w|Wd S d S )Nr   r   )
r_   rF   r`   ra   r&   r,   rb   rd   re   r   )r0   rf   limitoffsetri   rg   rh   rj   rk   rl   rm   rn   ro   rp   s                 r6   _find_key_manyzIU_HashIndex._find_key_many   s     11#66.)))L%%d&;<<	 	?)00;;A>H 	! 	!FJFVFVG# G#C&%fe
 T]**||!  "     	!  	! 
!FJFVFVG# G#C&%fe
 T]**||$eT69999
  "     	! 	! 	! 	! 	!s$   ;B2 2
B?>B?D
 

DDc                 j    t          t          |          | j        z            | j        z  | j        z   S rT   )abshashr   r&   r.   r0   rf   s     r6   r_   z IU_HashIndex._calculate_position   s=    499]# $ $&*&;<>BoN 	Nr7   c                 L   |}	 | j                             |           | j                             | j                  }	 | j                            |          \  }}}}}}	n"# t          j        $ r t          d          w xY w||k    rn|	st          d          |	}|||||||	fS )
        Locate position of the key, it will iterate using `next` field in record
        until required key will be find.

        :param key: the key to locate
        :param start: position to start from
        Tz	Not found)	rF   r`   ra   r(   r-   rb   r$   errorr   )
r0   rf   rm   ri   datark   rl   rn   ro   rp   s
             r6   rd   zIU_HashIndex._locate_key   s     	%Lh'''<$$T%9::D!<@<M<T<T= =9udFEE< ! ! !"! ! !! || %&{333$H#	%$ tVUBBs   !A   A?c                 X   |}	 | j                             |           | j                             | j                  }	 | j                            |          \  }}}}}	}
n#  t          d|d|d          xY w||k    r||k    rn|
st          d|d|d          |
}||||||	|
fS )z
        Locate position of the doc_id, it will iterate using `next` field in record
        until required key will be find.

        :param doc_id: the doc_id to locate
        :param key: key value
        :param start: position to start from
        TzDoc_id 'z' for 'z' not found)rF   r`   ra   r(   r-   rb   r   )r0   rk   rf   rm   ri   r|   l_doc_idrl   rn   ro   rp   s              r6   r*   zIU_HashIndex._locate_doc_id   s    	%Lh'''<$$T%9::D3>B>O>V>V? ?;%fee3#m%+VVSSS%2 3 3 36!!esll %'-)/)6 7 7 7  %H#	%$ tVUBBs   !A   A8c                 ,   |}	 | j                             |           | j                             | j                  }| j                            |          \  }}}}}}|r|| j        k    r(| j                                         | j        z
  ||||||fS |})
        Find a place to where put the key. It will iterate using `next` field in record, until
        empty `next` found

        :param start: position to start from
        )rF   r`   ra   r(   r-   rb   re   tell)	r0   rm   ri   r|   rk   rl   rn   ro   rp   s	            r6   _find_placezIU_HashIndex._find_place  s     
	!Lh'''<$$T%9::D8<8I8P8P9 95FE5$ !Fdm33|((  ()*0%feT T !
	!r7   c           
         |p| j         }|                     |          }| j                            |           | j                            | j                  }|r!| j                            |          d         }nt          d|z            | 	                    |||          \  }	}
}}}}}| j                            |	           | j        
                    | j                            ||||||                     |                                  | j                            |           | j	                            |           dS Nr   Location '%s' not foundT)STATUS_Or_   rF   r`   ra   r&   r,   rb   r   r*   rL   r-   packflushr)   delete)r0   rk   rf   u_startu_sizeu_statusrg   rh   ri   rj   _doc_id_keyrm   rn   ro   rp   s                   r6   updatezIU_HashIndex.update+  sH   ,t}11#66.)))L%%d&;<<	 	C)00;;A>HH86ABBB>B>Q>QC?# ?#;'4fe(###""63#(* *	+ 	+ 	+ 	

c"""""6***tr7   c                    |p| j         }|                     |          }| j                            |           | j                            | j                  }|r!| j                            |          d         }nd}|r	 |                     |||          \  }	}
}}}}}| j                            |	           | j        	                    | j
                            ||||||                     n# t          $ r |                     |          \  }	}
}}}}}| j                            dd           | j                                        }| j        	                    | j
                            ||||||                     | j                            |	           | j        	                    | j
                            |
|||||                     Y nw xY w|                                  | j                            |           | j                            |           dS | j                            dd           | j                                        }|| j        k     r8| j                            | j                   | j                                        }| j        	                    | j
                            |||||d                     | j                            |           | j                            |           | j        	                    | j                            |                     |                                  dS Nr   r   T)r   r_   rF   r`   ra   r&   r,   rb   r*   rL   r-   r   r   r   r   r   r   r)   r/   )r0   rk   rf   rm   rn   ro   rg   rh   ri   rj   r   r   _start_size_statusrp   wrote_ats                    r6   insertzIU_HashIndex.insert@  sh   (4=11#66.)))L%%d&;<<	  	)00;;A>HHH .	3IMI\I\CJ+ J+F'4  !!(+++""%**63tV+02 23 3 3 3 ! ? ? ?IMIYIYJ JF'4!!!Q'''<,,..""%**63tV+02 23 3 3 !!(+++""%**7D&%+2H> >? ? ? ? ??$ JJLLL&&v...N!!$''' 4 La###|((**H $/))!!$/222<,,..L!&&vsE4KKM M M N!!#&&&Ln---Lt166x@@AAAJJLLL4s   C2 2C#GGc                 R    |                      |                     |                    S rT   )r)   make_keyrx   s     r6   getzIU_HashIndex.get{  s     ~~dmmC00111r7   c                 V    |                      |                     |          ||          S rT   )rt   r   )r0   rf   rr   rs   s       r6   get_manyzIU_HashIndex.get_many~  s&    ""4==#5#5ufEEEr7   c              #     K   | j                             | j                   |rg| j                             | j                  }|snE	 | j                            |          \  }}}}}}	|| j        k    r|dz  }n# t          $ r Y nw xY w|g|rt| j                             | j                  }|sd S 	 | j                            |          \  }}}}}}	|| j        k    r|||||fV  |dz  }n# t          $ r Y d S w xY w|rd S d S Nr   	rF   r`   r/   ra   r(   r-   rb   re   r   )
r0   rr   rs   rh   rk   rf   rm   rn   ro   rp   s
             r6   allzIU_HashIndex.all  s     $/*** 	 ))$*>??I  :>:K:R:R; ;7UD&%
 T]**aKF	 "     	   	))$*>??I :>:K:R:R; ;7UD&%
 T]** #udF::::QJE "     	 	 	 	 	$   !A9 9
BB1!C, ,
C:9C:c           
      $   || j         k    r| j                            |           | j                            | j                  }|r| j                            |          \  }}}}}	}
| j                            |           | j                            | j                            |||||	|                     | 	                                 |r| j                            |           | j                            | j                  }|r| j                            |          \  }}}}}	}
| j                            |           | j                            | j                            |||||	|
                     | 	                                 d S rT   )
r/   rF   r`   ra   r(   r-   rb   rL   r   r   )r0   rf   pos_prevpos_nextr|   rk   rl   rm   rn   ro   rp   s              r6   	_fix_linkzIU_HashIndex._fix_link  s   t&&Lh'''<$$T%9::D <@<M<T<T= =9udFE!!(+++""%**65%v+35 56 6 6 

 
	Lh'''<$$T%9::D <@<M<T<T= =9udFE!!(+++""%**65%v+02 23 3 3 

r7   c           
      ~   |                      |          }| j                            |           | j                            | j                  }|r!| j                            |          d         }nt                      |                     |||          \  }}	}
}}}}| j                            |           | j        	                    | j
                            ||||| j        |                     |                                  | j                            |           | j                            |           dS )Nr   T)r_   rF   r`   ra   r&   r,   rb   r   r*   rL   r-   r   re   r   r)   r   )r0   rk   rf   rm   rn   rg   rh   ri   rj   r   r   ro   rp   s                r6   r   zIU_HashIndex.delete  s7   11#66.)))L%%d&;<<	 	()00;;A>HH &'''>B>Q>QC?# ?#;'4fe(###""63tT]#(* *	+ 	+ 	+ 	

c"""""6***tr7   c                    |s| j         }|                     | j        | j        dz   |          }|                                 |                                 }	 	 t          |          \  }}}}}n# t          $ r Y nw xY w| j        j	        
                    |           | j        j	                            |          }	|j        j	                                        }
|j        j	                            |	           |                    |||
||           |                                 | j        }|                                  t!          j        t$          j                            |j        |j        dz             t$          j                            | j        | j        dz                        t!          j        t$          j                            |j        |j        dz             t$          j                            | j        | j        dz                        |                                  || _        |                     t/          |                     |                                  |                                  dS )N_compact)r   Tr<   _stor)r2   )r   r5   r1   r2   rR   r   nextStopIterationr"   _fr`   ra   r   rL   r   close_indexshutilmover@   rA   rC   rI   _save_paramsrK   r9   rV   )r0   r   compact_indgenrk   rf   rm   rn   ro   valuestart_original_names               r6   compactzIU_HashIndex.compact  sL    	%}HnnT\%)Y%;.6 % 8 8 	  """hhjj		B37990UD&&    LO  '''LO((..E (+0022F"((///vsFD&AAA		B 	!!!	GLL,k.>.HIIGLLty7':;;	= 	= 	= 	GLL,k.>.HIIGLLty7':;;	= 	= 	= 	!	$M222333ts   A/ /
A<;A<c                 Z    t          |t                    r|n|                    d          S )Nutf8)r   bytesencoderx   s     r6   r   zIU_HashIndex.make_key  s'     e,,Dss#**V2D2DDr7   c                 
    d|fS )N   1 r0   r|   s     r6   make_key_valuezIU_HashIndex.make_key_value  s    Tzr7   c                 j    | j                                          | j                                         d S rT   )r)   clearr*   rH   s    r6   rV   zIU_HashIndex._clear_cache  s1    !!#####r7   c                 ~    t          t          |                                            |                                  d S rT   )r   r   r   rV   r:   s    r6   r   zIU_HashIndex.close_index  s7    lD!!--///r7   )r   r   Nr   )r   r   r   r   NrT   r   r   r   r   )r    
__module____qualname____doc__r   r9   rI   rR   rU   rG   rO   r)   rt   r_   rd   r*   r   r   r   r   r   r   r   r   r   r   r   rV   r   __classcell__r5   s   @r6   r   r   ,   s         $3!#+L +L +L +L +L +LZL L L L L    "        3 3 32!! !! !! !!FN N N
C C C@C C C<! ! !(   *9 9 9 9v2 2 2F F F F   8  4   ,& & & &PE E E  $ $ $        r7   r   c                        e Zd ZdZ	 d fd	Zd Zd Zd Zd Zdd
Z	ddZ
ddZd ZddZd Zd Zd Zd Zd Z xZS )IU_UniqueHashIndexa4  
    Index for *unique* keys! Designed to be a **id** index.

    That class is for Internal Use only, if you want to use UniqueHashIndex just subclass the :py:class:`UniqueHashIndex` instead this one.

    That design is because main index logic should be always in database not in custom user indexes.
    
<32s8sIIcIc                     d|v rt          d           t          t          |           j        |||g|R i | t          | _        d S )Nrf   z-UniqueHashIndex doesn't accept key parameter')r   r   r   r   r
   
create_keyr0   r1   r2   r'   argskwargsr5   s         r6   r   zIU_UniqueHashIndex.__init__  s     F??-?A A A	 	 	Wd,=	P@D	P 	P 	PHN	P 	P 	P'r7   c                 D   |                      |          }| j                            |           | j                            | j                  }|rE| j                            |          d         }|                     ||          \  }}}}}	}
}||||	|
fS dddd| j        fS r^   )	r_   rF   r`   ra   r&   r,   rb   rd   rc   )r0   rf   rg   rh   ri   rj   rl   revrm   rn   ro   rp   s               r6   r)   zIU_UniqueHashIndex._find_key  s     11#66.)))L%%d&;<<	 	3)00;;A>H?C?O?OX@ @<HeS%vu#udF22q!T]22r7   c                     t                      rT   NotImplementedErrorr0   r   r   s      r6   rt   z!IU_UniqueHashIndex._find_key_many.      !###r7   c                 \   |}	 | j                             |           | j                             | j                  }| j                            |          \  }}}}}}	||k    rt          d|z            |	r|| j        k    r(| j                                         | j        z
  ||||||	fS |	})r   TzThe '%s' key already exists)	rF   r`   ra   r(   r-   rb   r   re   r   )
r0   rm   rf   ri   r|   rl   r   rn   ro   rp   s
             r6   r   zIU_UniqueHashIndex._find_place1  s     	!Lh'''<$$T%9::D595F5M5M6 62E3tVU||$%BS%HIII !Fdm33|((  ()*/eT65Q Q !	!r7   c                    |}	 | j                             |           | j                             | j                  }	 | j                            |          \  }}}}}}	n%# t          j        $ r t          d|z            w xY w||k    rn|	st          d|z            |	}| j         	                                | j        z
  ||||||	fS )rz   Tr   )
rF   r`   ra   r(   r-   rb   r$   r{   r   r   )
r0   rf   rm   ri   r|   rl   r   rn   ro   rp   s
             r6   rd   zIU_UniqueHashIndex._locate_keyH  s    	%Lh'''<$$T%9::DD9=9J9Q9Q: :6sE4< D D D"#<s#BCCCD|| %&'@3'FGGG$H!	%" |   
 
 !"'eT65I 	Is   !A   "Br   Nc           
      x   |p| j         }|                     |          }| j                            |           | j                            | j                  }|r!| j                            |          d         }nt          d|z            | 	                    ||          \  }	}
}}}}}|dk    r|}|dk    r|}| j                            |	           | j        
                    | j                            ||||||                     |                                  | j                            |           dS r   )r   r_   rF   r`   ra   r&   r,   rb   r   rd   rL   r-   r   r   r)   r   )r0   rf   r   r   r   r   rg   rh   ri   rj   r   _revrm   rn   ro   rp   s                   r6   r   zIU_UniqueHashIndex.updatee  sI   ,t}11#66.)))L%%d&;<<	  	@)00;;A>HH83>???;?;K;K< <8$eT65a<<GQ;;F(###""3WfhNN	P 	P 	P

c"""tr7   c           
         |p| j         }|                     |          }| j                            |           | j                            | j                  }|r!| j                            |          d         }nd}|rM|                     ||          \  }	}
}}}}}| j                            dd           | j        	                                }|| j
        k     r8| j                            | j
                   | j        	                                }| j                            | j                            ||||||                     | j                            |	           | j                            | j                            |
|||||                     |                                  | j                            |
           dS | j                            dd           | j        	                                }|| j
        k     r8| j                            | j
                   | j        	                                }| j                            | j                            |||||d                     | j                            |           | j                            | j                            |                     |                                  | j                            |           dS r   )r   r_   rF   r`   ra   r&   r,   rb   r   r   r/   rL   r-   r   r   r)   r   )r0   rf   r   rm   rn   ro   rg   rh   ri   rj   r   r   r   r   r   rp   r   s                    r6   r   zIU_UniqueHashIndex.insert}  s   (4=11#66.)))L%%d&;<<	  	)00;;A>HHH )	BFBRBR#C C?HdD&%%La###|((**H $/))!!$/222<,,..L!&&sCfeLLN N N Lh'''L!&&tT65''/1 12 2 2 JJLLLN!!$'''4 La###|((**H $/))!!$/222<,,..L!&&sCfaHHJ J J Ln---Lt166x@@AAAJJLLLN!!#&&&4r7   r   c              #     K   | j                             | j                   |rg| j                             | j                  }|snE	 | j                            |          \  }}}}}}	|| j        k    r|dz  }n# t          $ r Y nw xY w|g|rt| j                             | j                  }|sd S 	 | j                            |          \  }}}}}}	|| j        k    r|||||fV  |dz  }n# t          $ r Y d S w xY w|rd S d S r   r   )
r0   rr   rs   rh   rk   r   rm   rn   ro   r   s
             r6   r   zIU_UniqueHashIndex.all  s     $/*** 	 ))$*>??I  9=9J9Q9Q: :6UD&$
 T]**aKF	 "     	   	))$*>??I 9=9J9Q9Q: :6UD&$
 T]** #udF::::QJE "     	 	 	 	 	r   c                     t                      rT   r   r   s      r6   r   zIU_UniqueHashIndex.get_many  r   r7   c                 B    |                      |d||| j                   d S )Ns   00000000)r   re   )r0   rf   rm   rn   s       r6   r   zIU_UniqueHashIndex.delete  s$    CeT4=AAAAAr7   c                 6   |d         }t          |t                    sQt          |t                    r|                    d          n|}	 t          |          }n#  t	          d          xY wt          |          dk    rt	          d          |d= |d= ||fS )N_idr   z%_id must be valid string/bytes object    zInvalid _id lenghtr   )r   r   r   r   r   len)r0   r|   r   s      r6   r   z!IU_UniqueHashIndex.make_key_value  s    5k#u%% 	=(23(<(<E#**V$$$#C=Cjj=1;= = =s88r>>-.BCCCKLDys   A A,c                 V    t          j        |            |                                  d S rT   )r   rU   rV   rH   s    r6   rU   zIU_UniqueHashIndex.destroy  s*    dr7   c                 8    | j                                          d S rT   )r)   r   rH   s    r6   rV   zIU_UniqueHashIndex._clear_cache  s    r7   c                 z    |r| j                             |          \  }}nd}d}|                     ||||          S Nr   r   )r"   r   r0   r   r   r   rm   rn   s         r6   insert_with_storagez&IU_UniqueHashIndex.insert_with_storage  G     	,--e44KE44ED{{3eT222r7   c                 z    |r| j                             |          \  }}nd}d}|                     ||||          S r   )r"   r   r   r   s         r6   update_with_storagez&IU_UniqueHashIndex.update_with_storage  r   r7   )r   r   rT   r   r   )r    r   r   r   r   r)   rt   r   rd   r   r   r   r   r   r   rU   rV   r   r   r   r   s   @r6   r   r     s:         $0( ( ( ( ( ("3 3 3"$ $ $! ! !.I I I:   04 4 4 4l   :$ $ $B B B B      3 3 33 3 3 3 3 3 3r7   r   c                   d     e Zd Z	 d fd	Zd Zd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Z xZS )DummyHashIndex
<32s4sIIcIc                 l     t          t          |           j        |||g|R i | t          | _        d S rT   )r   r   r   r
   r   r   s         r6   r   zDummyHashIndex.__init__  sR     	-nd##,Wd<M 	>.2	> 	> 	>6<	> 	> 	>'r7   c                     dS NTr   r   s      r6   r   zDummyHashIndex.update	      tr7   c                     dS r   r   r   s      r6   r   zDummyHashIndex.insert  r   r7   c                     t           rT   r   r   s      r6   r   zDummyHashIndex.all      r7   c                     t           rT   )r   r   s      r6   r   zDummyHashIndex.get  s    r7   c                     t           rT   r   r   s      r6   r   zDummyHashIndex.get_many  r   r7   c                     d S rT   r   r   s      r6   r   zDummyHashIndex.delete      r7   c                     dddifS )N1_r   r   r   s     r6   r   zDummyHashIndex.make_key_value  s    S!H}r7   c                     d S rT   r   rH   s    r6   rU   zDummyHashIndex.destroy  r   r7   c                     d S rT   r   rH   s    r6   rV   zDummyHashIndex._clear_cache!  r   r7   c                 l    | j         st                      | _         | j                                          d S rT   )r"   r   rE   rH   s    r6   rG   zDummyHashIndex._open_storage$  s1    | 	*'>>DLr7   c                 l    | j         st                      | _         | j                                          d S rT   )r"   r   r\   rH   s    r6   rO   zDummyHashIndex._create_storage)  s1    | 	*'>>DLr7   )r   )r    r   r   r   r   r   r   r   r   r   r   rU   rV   rG   rO   r   r   s   @r6   r   r     s         $0( ( ( ( ( (                    
      r7   r   c                   V     e Zd ZdZ fdZd
 fd	Zd
 fd	Zd fd	Z fdZd	 Z	 xZ
S )IU_MultiHashIndexz
    Class that allows to index more than one key per database record.

    It operates very well on GET/INSERT. It's not optimized for
    UPDATE operations (will always readd everything)
    c                 H     t          t          |           j        |i | d S rT   )r   r  r   )r0   r   r   r5   s      r6   r   zIU_MultiHashIndex.__init__6  s,    /&&/@@@@@@r7   Nc                    |p| j         }t          |t          t          f          rt	          |          }n%t          |t                    st	          |g          }t          t          |           j        }|D ]} ||||||           dS r   )r   r   listtuplesetr   r  r   )	r0   rk   rf   rm   rn   ro   inscurr_keyr5   s	           r6   r   zIU_MultiHashIndex.insert9  s    (4=cD%=)) 	c((CCC%% 	se**C%t,,3 	7 	7HC%v6666tr7   c                    |p| j         }t          |t          t          f          rt	          |          }n%t          |t                    st	          |g          }t          t          |           j        }|D ]} ||||||           d S rT   )r   r   r	  r
  r  r   r  r   )	r0   rk   rf   r   r   r   updr  r5   s	           r6   r   zIU_MultiHashIndex.updateD  s    ,t}cD%=)) 	c((CCC%% 	se**C%t,,3 	= 	=HC'68<<<<	= 	=r7   r   c                    t          |t          t          f          rt          |          }n%t          |t                    st          |g          }t	          t
          |           j        }|D ]} |||||           d S rT   )r   r	  r
  r  r   r  r   )r0   rk   rf   rm   rn   r   r  r5   s          r6   r   zIU_MultiHashIndex.deleteN  s    cD%=)) 	c((CCC%% 	se**C($//6 	2 	2HF68UD1111	2 	2r7   c                 T    t          t          |                               |          S rT   )r   r  r   )r0   rf   r5   s     r6   r   zIU_MultiHashIndex.getW  s"    &--11#666r7   c                     t                      rT   r   r   s     r6   r   z IU_MultiHashIndex.make_key_valueZ  r   r7   rT   r   )r    r   r   r   r   r   r   r   r   r   r   r   s   @r6   r  r  /  s         A A A A A	 	 	 	 	 	= = = = = =2 2 2 2 2 27 7 7 7 7$ $ $ $ $ $ $r7   r  c                       e Zd ZdZdS )	HashIndex>
    That class is designed to be used in custom indexes.
    Nr    r   r   r   r   r7   r6   r  r  b            	Dr7   r  c                       e Zd ZdZdS )UniqueHashIndexz`
    That class is designed to be used in custom indexes. It's designed to be **id** index.
    Nr  r   r7   r6   r  r  i  r  r7   r  c                       e Zd ZdZdS )MultiHashIndexr  Nr  r   r7   r6   r  r  p  s           r7   r  )#r@   rM   rD   r$   r   codernitydb3.indexr   r   r   r   r   r   codernitydb3.rr_cacher	   codernitydb3.miscr
   codernitydb3.storager   r   codernitydb3.envr   r   codernitydb3r   patch_cache_rrr   ImportErrorr   r   r   r   r  r  r  r  r   r7   r6   <module>r$     s  & 
			  				  = = = = = = = = = = = = = = = = , + + + + + + + + + + + 9 9 9 9 9 9 9 9 , , , , , ,?{## 7""""""E5666%((((((( % % %$$$$$$$$%U U U U U5 U U Upv3 v3 v3 v3 v3 v3 v3 v3r/ / / / /\ / / /d,$ ,$ ,$ ,$ ,$ ,$ ,$ ,$f	 	 	 	 	 	 	 		 	 	 	 	( 	 	 	    &     s   ,A3 3B B