
    -i                     .    d dl mZ  G d de          ZdS )    )Indexc                   v     e Zd Z fdZd Ze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 )ShardedIndexc                    t          t          |                               ||           	 |                    d          | _        n# t
          $ r
 d| _        Y nw xY w	 |                    d          }|| _        n# t
          $ r t          d          w xY wd|v r|                    d          | _        nd| _         | j	        |i | g | _
        dS )a  
        There are 3 additional parameters. You have to hardcode them in your custom class. **NEVER** use directly

        :param int sh_nums: how many shards should be
        :param class ind_class: Index class to use (HashIndex or your custom one)
        :param bool use_make_keys: if True, `make_key`, and `make_key_value` will be overriden with those from first shard

        The rest parameters are passed straight to `ind_class` shards.

        sh_nums   	ind_classzind_class must be givenuse_make_keysFN)superr   __init__popr   KeyErrorr	   	Exceptionr
   _set_shard_dataspatchers)selfdb_pathnameargskwargsr	   	__class__s         X/var/www/html/speakWrite/venv/lib/python3.11/site-packages/codernitydb3/sharded_index.pyr   zShardedIndex.__init__   s    	lD!!**7D999	!::i00DLL 	 	 	DLLL		'

;//I 'DNN  	7 	7 	75666	7 f$$!'O!<!<D!&Dt.v...s   A AAA< <Bc                     i  _         i  _         j        }d} fdt           j                  D             D ]N} | j        |g|R i | j         |<    j         |          j        d|z  <    j         |          j        |<   |dz  }O j        s. j         d         j         _         j         d         j         _        d _	        d S )Nr   c                 >    g | ]}j         t          |          z   S  )r   str).0xr   s     r   
<listcomp>z1ShardedIndex._set_shard_datas.<locals>.<listcomp>>   s&    HHHq	CFF*HHH    s   %02x   )
shardsshards_rr	   ranger   r   r
   make_keymake_key_value	last_used)r   r   r   r	   ish_names   `     r   r   zShardedIndex._set_shard_datas8   s    N	HHHHE$,4G4GHHH 	 	G&Yt|WNtNNNvNNDKN)-QDM'A+&#{1~DM!FAA! 	@ KN3DM"&+a."?Dr    c                 4    | j         | j                 j        }|S N)r"   r'   storage)r   sts     r   r,   zShardedIndex.storageK   s    [(0	r    c                 B    t          | j        | j                 |          S r+   )getattrr"   r'   )r   r   s     r   __getattr__zShardedIndex.__getattr__P   s    t{4>2D999r    c                 f    | j                                         D ]}|                                 d S r+   )r"   values
open_indexr   currs     r   r3   zShardedIndex.open_indexS   s<    K&&(( 	 	DOO	 	r    c                 f    | j                                         D ]}|                                 d S r+   )r"   r2   create_indexr4   s     r   r7   zShardedIndex.create_indexW   s>    K&&(( 	  	 D	  	 r    c                 f    | j                                         D ]}|                                 d S r+   )r"   r2   destroyr4   s     r   r9   zShardedIndex.destroy[   8    K&&(( 	 	DLLNNNN	 	r    c                 f    | j                                         D ]}|                                 d S r+   )r"   r2   compactr4   s     r   r<   zShardedIndex.compact_   r:   r    c                 f    | j                                         D ]}|                                 d S r+   )r"   r2   reindexr4   s     r   r>   zShardedIndex.reindexc   r:   r    c              /   j   K   | j                                         D ]} |j        |i |D ]}|V  d S r+   )r"   r2   allr   r   r   r5   nows        r   r@   zShardedIndex.allg   s]      K&&(( 	 	Dtx000  					 	r    c              /   j   K   | j                                         D ]} |j        |i |D ]}|V  d S r+   )r"   r2   get_manyrA   s        r   rD   zShardedIndex.get_manyl   s]      K&&(( 	 	D$t}d5f55  					 	r    c                     t                      r+   )NotImplementedError)r   datas     r   r&   zShardedIndex.make_key_valueq   s    !###r    c                 Z    t          |t                    r|                    d          }|S )Nutf8)
isinstancer   encode)r   keys     r   r%   zShardedIndex.make_keyt   s*    c3 	%**V$$C
r    )__name__
__module____qualname__r   r   propertyr,   r0   r3   r7   r9   r<   r>   r@   rD   r&   r%   __classcell__)r   s   @r   r   r      s            >  &   X: : :               
  
$ $ $      r    r   N)codernitydb3.indexr   r   r   r    r   <module>rS      sW   & % $ $ $ $ $
_ _ _ _ _5 _ _ _ _ _r    