
    d`                    "   d Z ddlZ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 ddl	m
Z ddl	mZ ddlZddl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 ddlm Z  ddl!m"Z" ddl#m$Z$m%Z%m&Z& ddl'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z.m/Z/m0Z0 ddl1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7 ddl8m9Z9 dZ:dZ;dZ<e<rddl-m=Z= dZ>dZ? e"dddd          Z@e?ZAe@ZBdZCdZDd ZE G d d ee(ejF                  ZF G d! d"ee(          ZG G d# d$ee(          ZH G d% d&ee(          ZIdS )'z Here is defined the Index class.    N)Path)perf_counter)process_time   )calc_chunksizecalcoptlevelsget_reduction_level	nextafterinftype)indexesextension)NotLoggedMixin)UIntAtomAtom)EArray)CArray)Filters)
CacheArrayLastRowArray
IndexArray)Group)	join_path)PerformanceWarning)is_idxidx2longlazyattr)nan_aware_gtnan_aware_genan_aware_ltnan_aware_lebisect_leftbisect_right)ObjectCachez2.1F)
show_stats	mergesortTzlib)	complevelcomplibshuffle
fletcher32)
int8int16int32int64uint8uint16uint32uint64float32float64l        c                 "   |                      d          }t          |          D ]\  }}|                    d          r nd                    |d |                   dz   |dd          z   }d                    ||dz   d                    }||fS )N/_i_   r   )split	enumerate
startswithjoin)indexpathnamenamesinametablepathnamecolpathnames         ,lib/python3.11/site-packages/tables/index.py_table_column_pathname_of_indexrC   O   s    $$EU##  4??5!! 	E	HHU2A2Y''#-QRR8M((5Q=))K;''    c                       e Zd ZdZdZed             Zed             Zed             Zej	        d             Zed             Z
ed             Zed	             Zed
             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Z	 	 	 	 	 	 	 	 	 dD fd	Z fdZd Zd ZdEdZdEd ZdEd!Z d" Z!dFd#Z"d$ Z#d% Z$d& Z%d' Z&dGd)Z'dHd*Z(dHd+Z)dHd,Z*dHd-Z+d. Z,d/ Z-d0 Z.dGd1Z/dHd2Z0d3 Z1d4 Z2d5 Z3dId6Z4dId7Z5d8 Z6d9 Z7d: Z8d; Z9d< Z:d= Z;d> Z<d? Z=d@ Z>dE fdA	Z?dB Z@dC ZA xZBS )JIndexa  Represents the index of a column in a table.

    This class is used to keep the indexing information for columns in a Table
    dataset (see :ref:`TableClassDescr`). It is actually a descendant of the
    Group class (see :ref:`GroupClassDescr`), with some added functionality. An
    Index is always associated with one and only one column in the table.

    .. note::

        This class is mainly intended for internal use, but some of its
        documented attributes and methods may be interesting for the
        programmer.

    Parameters
    ----------
    parentnode
        The parent :class:`Group` object.

        .. versionchanged:: 3.0
           Renamed from *parentNode* to *parentnode*.

    name : str
        The name of this node in its parent group.
    atom : Atom
        An Atom object representing the shape and type of the atomic objects to
        be saved. Only scalar atoms are supported.
    title
        Sets a TITLE attribute of the Index entity.
    kind
        The desired kind for this index.  The 'full' kind specifies a complete
        track of the row position (64-bit), while the 'medium', 'light' or
        'ultralight' kinds only specify in which chunk the row is (using
        32-bit, 16-bit and 8-bit respectively).
    optlevel
        The desired optimization level for this index.
    filters : Filters
        An instance of the Filters class that provides information about the
        desired I/O filters to be applied during the life of this object.
    tmp_dir
        The directory for the temporary files.
    expectedrows
        Represents an user estimate about the number of row slices that will be
        added to the growable dimension in the IndexArray object.
    byteorder
        The byteorder of the index datasets *on-disk*.
    blocksizes
        The four main sizes of the compound blocks in index datasets (a low
        level parameter).

    INDEXc                 &    ddddd| j                  S )zThe kind of this index.
ultralightlightmediumfullr            )indsizeselfs    rB   kindz
Index.kind   s'      G( ((,6 	6rD   c                     | j         S )zSFilter properties for this index - see Filters in
        :ref:`FiltersClassDescr`.)
_v_filtersrR   s    rB   filterszIndex.filters   s     rD   c                 .    t          | j        dd          S )zWhether the index is dirty or not.
        Dirty indexes are out of sync with column data, so they exist but they
        are not usable.
        DIRTYF)getattr_v_attrsrR   s    rB   dirtyzIndex.dirty   s     t}gu555rD   c                     | j         t          |          }}|| j        _        | j        j        }|s|r|                                 |r|s|                                 d S d S d S N)r\   boolr[   rY   table_condition_cachenailunnail)rS   r\   wasdirtyisdirtyconditioncaches        rB   r\   zIndex.dirty   s     JU'# 4 	"G 	"!!! 	$G 	$!!#####	$ 	$ 	$ 	$rD   c                     t          | j                  \  }}| j                            |          }|j                            |          }|S )zQThe Column (see :ref:`ColumnClassDescr`) instance for the indexed
        column.)rC   _v_pathname_v_file	_get_nodecols_g_col)rS   	tablepath
columnpathr`   columns        rB   ro   zIndex.column   sN    
 !@! !	:&&y11"":..rD   c                 h    t          | j                  \  }}| j                            |          }|S )z.Accessor for the `Table` object of this index.)rC   rh   ri   rj   )rS   rm   rn   r`   s       rB   r`   zIndex.table   s9     !@! !	:&&y11rD   c                      | j         | j        z  S )z%The number of blocks in a superblock.)superblocksize	blocksizerR   s    rB   nblockssuperblockzIndex.nblockssuperblock   s     "dn44rD   c                      | j         | j        z  S )z The number of slices in a block.)rs   	slicesizerR   s    rB   nslicesblockzIndex.nslicesblock        ~//rD   c                      | j         | j        z  S )z The number of chunks in a slice.)rv   	chunksizerR   s    rB   nchunkslicezIndex.nchunkslice   rx   rD   c                 ^    | j         | j        z
  }|| j        z  }|| j        z  dk    r|dz  }|S )z)The total number of superblocks in index.r   r   )	nelementsnelementsILRrr   rs   rS   r}   nblockss      rB   nsuperblockszIndex.nsuperblocks   s@     NT%66	t22t~%))qLGrD   c                 ^    | j         | j        z
  }|| j        z  }|| j        z  dk    r|dz  }|S )z$The total number of blocks in index.r   r   )r}   r~   rs   r   s      rB   r   zIndex.nblocks   s?     NT%66	t~-t~%))qLGrD   c                      | j         | j        z  S )z'The number of complete slices in index.)r}   rv   rR   s    rB   nsliceszIndex.nslices   rx   rD   c                      | j         | j        z  S )z'The number of complete chunks in index.)r}   rz   rR   s    rB   nchunkszIndex.nchunks   rx   rD   c                     | j         | j        fS )z1The shape of this index (in slices and elements).)nrowsrv   rR   s    rB   shapezIndex.shape   s     
DN++rD   c                 X    | j         dk    o| j        dk    o| j        j        | j        k    S )z8Whether a temporary file for indexes is required or not.r   r   )rQ   optlevelr`   r   rv   rR   s    rB   temp_requiredzIndex.temp_required   s6     q  2!2
 4>1	3rD   c                 .    | j         dk    o
| j        dk    S )z@Whether we should try to build a completely sorted index or not.rP   	   )rQ   r   rR   s    rB   want_complete_sortzIndex.want_complete_sort   s     |q 7T]a%77rD   c                     | j         dk    rdS | j        dk     rdS d| j        v r| j        j        S |                     | dd           | j        dk    S )zWhether the index is completely sorted or not.

        .. versionchanged:: 3.0
           The *is_CSI* property has been renamed into *is_csi*.

        r   FrP   is_csiN)r}   rQ   r[   r   compute_overlaps	noverlapsrR   s    rB   r   zIndex.is_csi  sg     >Q5<!5t}$$='' 	dD%000~""rD   c                 &    | j         j        d         S )z0The number of rows that fits in a *table* chunk.r   )r`   
chunkshaperR   s    rB   nrowsinchunkzIndex.nrowsinchunk  s     z$Q''rD   c                    t          | j        | j                  }| j        dk    r-d}| j        ||z  k    rt          j        | j        |z            }n9| j        dk    r-d}| j        ||z  k    rt          j        | j        |z            }n	 |S )z/Return the length of a bucket based index type.r      rN   i   )minr   rz   rQ   rv   mathceilrs   )rS   lbucketmaxnbs      rB   r   zIndex.lbucket  s    
 d'88<1 E~//)DNU$:;;\Q E~//)DNU$:;; rD   N r   Tc                 :   d | _         	 || _        	 || _        	 |	| _        	 |
dv r|
| _        nt
          j        | _        	 |A|j        j        | _        |j        | _        	 ddddd|         }|dv s
J d            || _	        	 d | _
        	 d | _        	 || _        	 d	| _        	 d | _        	 d | _        	 d | _        	 d | _        	 d | _        	 t&          | _        	 d
| _        	 d| _        	 ddlm} || _        	 t3                                          |||||           d S )N)littlebigr   rN   rO   rP   )rI   rJ   rK   rL   rM   zindsize should be 1, 2, 4 or 8!Tr   )	open_file)
_v_versionr   tmp_direxpectedrows	byteordersysdtypebasetyperQ   r   r}   
blocksizes
dirtycacherr   rs   rv   rz   tmpfilenameopt_search_typesr   tproffiler   	_openFilesuper__init__)rS   
parentnoder?   atomtitlerT   r   rW   r   r   r   r   newrQ   r   	__class__s                  rB   r   zIndex.__init__7  sr    / 44(;)))&DNN ]DN2DJ	DIG  !q!E EEIKGl***,M***"DLA
6C$H="4///, 0L	H
5######"ET5#w?????rD   c                 "   | j         rt          | _        t                                                       | j         s4| j        }| j        }t          |j                  | _        t          |j                  | _        t          |j	                  | _	        t          |j
                  | _
        | j        | j        | j	        | j
        f| _        t          |j                  | _        | j        }| j        }|j        j        | _        |j        j        | _        |j        j        | _        | j	        |j        d         k    s
J d            | j
        |j        d         k    s
J d            | j        dv s
J d            |dk    rVt          |j                  | _        t          | j        j        j                  }t          | j        j        j                  }nd| _        | j        d         }|}|j        | _        | j        | j	        z  |z   | _        || _        || _        |dk    r| xj        dz  c_        | j
        | j        z  }|dz
  |z  }|dk     rd}|d	z  }| j        |||z            | _        d S d| _        d| _        d| _        d| _        t?          j         | j                  }	| j!        }
| j        'tE          | j#        | j        | j        | 
          | _        | j        \  | _        | _        | _	        | _
        tH          rtK          d| j                   tM          | j        | j        | j	        | j
                  | _        | j
        | j        z  }| j	        | j        z  }tO          j(        | j                  | j        _        tO          j(        | j                  | j        _        tO          j)        | j	                  | j        _	        tO          j)        | j
                  | j        _
        | j        | j        _        | j        | j        _        tU          | d|	d|
| j+                  }tU          | dtY          | j                  d|
| j+                   t[          | d|	dd|
| j#        | j	        z  | j+                   t]          | d|	dd|
| j+        d           |dz
  |z  }t[          | d|	d|fd|
| j/        d|f| j+        	  	         t]          | d|	dd|
| j+        d           t]          | d|	dd|
| j+        d           t]          | d |	dd!|
| j+        d           |d	z   |z   f}ta          | d"|	|d#|
|f| j+                  }| j	        f}ta          | d$tY          | j                  |d%|
| j
        f| j+                  }d|j        _        d|j        _        d | _        tO          j1        | j        tN          j2        &          | _3        	 tO          j1        | j        tN          j2        &          | _4        	 | j5        r| 6                                 d S d S )'Nr   zWrong slicesizezWrong chunksizerM   zWrong indices itemsizez2.0r   r   rN   )nodezblocksizes:sortedzSorted ValuesindicesitemsizezNumber of chunk in tablerangesr   rN   zRange Values)r   mrangesr   Median rangesF)r   _logboundszBoundary ValuesaboundszStart boundszboundsz
End boundsmboundsMedian boundssortedLRzLast Row sorted values + bounds	indicesLRzLast Row indicesr   r   )7_v_new	obversionr   r   _g_post_init_hookr[   intrr   rs   rv   rz   r   r   r   r   r   r   r   r   rQ   r   _v_chunkshape	reductionr   attrsr}   r   r   nelementsSLRr~   beboundsr   
from_dtyperW   r   r   debugprintr	   npr1   r0   r   r   r   r   r   r   r   emptyr,   startslengthsr   create_temp)rS   
idxversionr   r   r   r   r~   
rchunksize	nboundsLRr   rW   
rslicesizenbounds_inslicer   r   r   r   s                   rB   r   zIndex._g_post_init_hook  sG   ; 	('DO!!### { .	JME #&e&:";";D 11DN 11DN 11DN#2DN#~t~?DO//DM[FlG*DJ(DI"<0DL>W]1%55557H555>W%:&   %  <<///1I///E!!!$U_!5!5"4=#6#@AA"4>#7#ABB!"#~b1+DJ!Z$.8<GDN ,D ,Da

a

4>9J%)j8I1}}	NI M\I557DMF 
 tz** , ?",!4=$,TK K KDO ,0?	)	dn	 	2-111,L$-I I^t~5
^t~5
 (*y1D'E'E$"$)DN";";"$)DN";";"$)DN";";!%"&. D(D/#T^5 5 	4Hdl$C$C$C-w	H 	H 	H 	44$6!^	- 	- 	- 	- 	tYdOWe	5 	5 	5 	5 &>j844!_)=$gt|'4>	C 	C 	C 	C
 	tYdNGe	5 	5 	5 	5tYdL'e	5 	5 	5 	5tYdOWe	5 	5 	5 	5 a/13j$ A '**..: : : ! {!)4<!@!@!@!&(:!(4>*;+/>	; ; ;	 $% $%	!  hTZrx@@@KxdjAAAJ  		 	rD   c                    t           rt                      }t           rt          d|           |                                }| j        }| j        }| j        }t           rt          d|           |dk    r+t          j        dt          |          d          ||z  z   }	n|dk    r%t          j        dt          |          d          }	nt          j
        t          |          d	|dz  z            }	| j        }
t          |
|||
z  z  |
z  z
            }d|	d|<   t          |||
          D ]}||
z   d
z
  |
z  |	|||
z   <   |dk    r|| j        z  |z  |
z  }|	|z  }	|dk    ra|dk    r[t          |          |k    sJ |                     | j        |d|                    |                     | j        |	d|                    t           rt          d|           t%          j        ||	           |d         }|d
k    rdt           rt          d|           |dd|                                         }t           rt          d|           |}t           rt          d|           |dk    rd| j        _        t           rt          d|           |||	fS )z9Compute an initial indices arrays for data to be indexed.zEntering initial_appendzBefore creating idxrP   r   r1   r   rO   r0   zuint%dr   rN   NzBefore keysortr   zBefore reductionzAfter reductionzAfter arr <-- reducFzExiting initial_append)profileclockr#   poprQ   rv   r~   r   arangelenr   r   r   rangerw   read_slice_lrr   r   r   keysortcopyr[   r   )rS   xarrnrowr   trefarrrQ   rv   r~   idxr   offsetr>   offset2larrreducs                   rB   initial_appendzIndex.initial_append  s     	77D 	80$777hhjj,N	( 	4,d333a<<)As3xxx8884);KKCC\\& )As3xxx888CC(3s88X1%=>>ClGTY-@%AW$LMNNFC&M69g66 B B&''kAo'%AAa'kM""!||  $"33y@GKwqLL\A-- s88l****t}c-<-.@AAAt~s=L=/ABBB 	/'... c***2wq==  5-t444)$))++E 4,d333C 80$777 !88#(DM  	7/666S#~rD   c                     t           rt                      }t           rt          d|           |                    d          }||z  }|| j        z  }|                    d          }t           rt          d|           |S )z+Perform final operations in 32-bit indices.zEntering final_idx32r1   r0   zExiting final_idx32)r   r   r#   astyper   )rS   r   r   r   s       rB   final_idx32zIndex.final_idx32h  s      	77D 	5-t444jj""v 	jj"" 	4,d333
rD   Fc                 z   t           rt                      }t           rt          d|           |s| j        r
| j        }d}n	| }| j        }|j        }|j        }|j        }|j	        }	|j
        }
|j        }|j        }|j        }|j        }|j        }|j        }|                     |||          \  }}}|                    |                    d|j                             | j        |z  }| j        }|                    |d         |gg           |
                    ||d|         g           |                    |dd|                    |                    ||dz
  d|                    ||dz  d|         }|                    |           |	                    ||dz           g           t           rt          d|           ~~t           rt          d|           | j        dk    r|                     ||| j        z            }|                    |                    d|j                             t           rt          d	|           ~|dz   | _        | j        | j        z  | _        d| _        d| _        | j        |j        _        | j        |j        _        d
| _        t           rt          d|           dS dS )z&Append the array to the index objects.zEntering appendr   r   NrN   zBefore deleting arr & smedianzAfter deleting arr & smedianrO   zBefore deleting idxTzExiting append)r   r   r#   r   tmpr   r   r   r   r   r   r   r   r   r   r   r   r   appendreshapesizerz   r{   rQ   r   rv   r}   r   r~   r   r   )rS   r   updater   wherer   r   r   r   r   r   r   r   r   r   r   r   r   r   r   csncssmedians                          rB   r   zIndex.append|  s     	77D 	0($/// 	'$, 	'HEIIEI----->O	,,T5)DDc3ckk!SX..///^y(A~&'''s26r6{m$$$s15b5z"""s26:2:'''bAgkrk"wq)*+++ 	>6=== 	=5t<<<<1""3(>??Cs{{1ch//000 	4,d333QY
dn4 $(#4 $($5	! 	/'.....	/ 	/rD   c                 &   t           rt                      }t           rt          d|           | j        }|s| j        r
| j        }d}n	| }| j        }|j        }|j        }| 	                    |||          \  }	}
}t          |
          }t          |          }| j        |z  }t          j        |
dd|         |	gf          | _        ||j        _        ||j        _        t          | j                  }| j        ||||z   <   |
|d|<   ~
| j        dk    r|                     ||| j        z            }||dt          |          <   ~|dz   | _        || j        z  |z   | _        || _        || _        d| _        t           rt          d|           dS dS )z/Append the array to the last row index objects.zEntering appendLRr   NrO   TzExiting appendLR)r   r   r#   r   r   r   r   r   r   r   r   rz   r   concatenater   r   r}   rQ   r   rv   r   r~   r   r   )rS   r   r  r   r   r  r   r   r   r   r   r   r   r~   r   r   s                   rB   append_last_rowzIndex.append_last_row  s     	77D 	2*D111 	'$, 	'HEIIEIO	>,,T5)DDc33xx3xx^y0
LLjL(9D6'BCC#/ $0	! dm$$8<lW445"%,<1""3(>??C"	)3s88)QY
/,>(( 	1)400000	1 	1rD   c                    | j         sdS |rd| _        nt          | _        d| _        d| _        t          | j        | j        | j                  }|\  }}}}t          rt          d|           | 
                                 	 |rt          |          D ]}|                     dd          r nl| j        dk    r0|                     dd          r nI|                     dd          r n1|                     dd	          r n|                     dd
          r nnK|r|                     dd          rn3|r|                     dd	          rn|r|                     dd
          rn	 | j        rD| j        dk    r|                                  | j        dk    rt!          j        dt$                     |                                  dS )zOptimize an index so as to allow faster searches.

        verbose
            If True, messages about the progress of the
            optimization process are printed out.

        NTr   z
optvalues:chunksmedianr   slicesstartstopz[OPSI was not able to achieve a completely sorted index.  Please report this to the authors.)r   verboser   
last_tover
last_noverr   r   r   rQ   r   create_temp2r   swapr   r   do_complete_sortwarningswarnUserWarningcleanup_temp)rS   r  opts	optmedian	optstartsoptstopsoptfullniters           rB   optimizezIndex.optimize  s%    ! 	F 	!DLL DL  T\4=$,GG26/	9h 	&,%%%	 "7^^  Eyy844 |a''  99Xx88 "!E99Xx88 "!Eyy733 yy622   yy844  yy733  yy622  " 	I~!!%%'''~!!;<GI I I
 	rD   c           	      
   | j         rt                      }t                      }| j        }| j        }|j        dd         }| j        }| j        }|dk    rHt          j	        | j
        d         | j
        d         g          }t          j        ||gf          }|dz  }|j        }	|j        }
|j        }|j        }t          j	        g | j                  }t          j	        g d| j        z            }t          j        |t          j                  }t)          |          D ]}t          j	        g | j                  }t          j	        g d| j        z            }||df         }t)          |dz   |          D ]}||         }|| j        k     r||k    s|| j        k    r||k    r.|| j        k     r||k     s
J d            |	||f         }n||k     s
J d            ||         }||df         }||k    r|| j        k     rFt          j        ||	||df         f          }t          j        ||
||df         f          }|||<   |}t          j        ||||         f          }t          j        ||||         f          }|||<   ||k    r|                     |||||         |          }|| j        k     rAt          j        ||	|||f         f          }t          j        ||
|||f         f          }n<t          j        ||||         f          }t          j        ||||         f          }|||<   || j        k     rOt          j        ||	|||         df         |f          }t          j        ||
|||         df         |f          }nJt          j        ||||         |         |f          }t          j        ||||         |         |f          }t-          j        ||           || j        k     rs|d|         |	|<   |d|         |
|<   |                     ||d|                    t3          |          t3          |          z   }||||z            }||||z            }Vt3          |          }||k    sJ d}||d|<   ||d|<   |d|         }t          j        |dd| j                 |d         gf          }||||t3          |          z   <   || _
        |dk    sJ |                     | j        d	| j                    | j         r7t9          d
t                      |z
  ddt                      |z
  d           dS dS )z>Bring an already optimized index into a complete sorted state.Nr   r   r   r   u%dr   z3Two slices cannot overlap completely at this stage!zdo_complete_sort()time: .4f	. clock: )r  r   cpuclockrv   r   r   r   r~   r   arrayr   r  r   r   r   r   r   rQ   zerosint_r   search_item_ltr   r   update_cachesr   rz   r   r   )rS   t1c1ssr   r   r   nelementsLRrangeslrr   r   r   r   sremainiremainr   r>   soverioverprev_endjstjnext_begnext_endnr   ssortedsindicessendsortedlrr   s                                  rB   r  zIndex.do_complete_sort8  s    < 	BB^hAAA,'??xq!14=3D EFFH^VhZ$899FqLG+<M	(2TZ000(2UT\%9:::rw777w K	) K	)AHRtz222EHRut|';<<<Ead|H1q5'** "$ "$Qi%%#))dl**sk/A/At|##888M $88%af~HH,,,M -,,'}H!!Q$<h&&4<'' "vag/G H H "wq#$$w7G/H I I$&q		' "xA/G H H "yQ7G/H I I$/q		((--c8Qq	3OOC4<'' "vaSj7I/J K K "wq#c'z7J/K L L "xC7H/I J J "yS7I/J K K #F1I4<.fQq	

]3U;= =>gam4e<> > .hvay'<=uEG G>iq	+(=>FH H $Wh7774<#CRCLq	%crc]
""1gcrcl3335zzCLL0!"R$Y,/"2b4i<0 LLK''''&! (	"1"#L[L1>.../(2,@B BDL[3x==%@@A ( qyyyy
 	dh(<dlKKK< 	MK577R<KKKhjj2oKKKLLLLL	M 	MrD   c                    d}d}d}| j         rt                      }t                      }|dk    r|                     |           n|dk    r|                     |           |r
d| d| d}nd| }|                     | j        || j                   \  }	}
}t          |
                                d	                   t          |
          z  }| j         r5t          d
t                      |z
  ddt                      |z
  d           |dk    rH| j
        d	k    r=| j        d	k    r2| j
        |z
  | j
        z  }| j        |	z
  | j        z  }|dk     r|dk     rdS || _
        |	| _        |	|k     rdS ||k     rdS d	|cxk    r|k     rn ndS dS )z7Swap chunks or slices using a certain bounds reference.(   g?g{Gz?r
  r  swap_()r   r"  r#  r$  g?TF)r  r   r%  swap_chunksswap_slicesr   r   r   nonzeror   r  r  )rS   whatmodethnoverthmultthtoverr+  r,  messagenovermulttoverrmult	tover_var	nover_vars                  rB   r  z
Index.swap  s    < 	BB8T""""XT""" 	%,d,,T,,,GG$dnnG#44Hgt| -  -eDLLNN1%&&T2< 	MK577R<KKKhjj2oKKKLLL8! 3 3!8K8K50DOCI50DOCI4I$4$4t7??46>>44urD   c           
         d| _         t          j        dd| j                  \  }| _        t          j        |           |                     | j        d          | _        | j        j	        x| _
        }| j        }| j        }| j        }d|f}t          j        | j                  }t#          |d||d|d|f	           t#          |d
t%          | j                  |d|d|f	           |dz
  |z  }d|f}t#          |d||d|||f	           d}t#          |d||d||f	           t#          |d||d||f	           t#          |d||d||f	           t#          |d|dd||df	           t#          |d|dd||f	           |dz   |z   f}t)          |d||d||f	           |f}t)          |dt%          | j                  |d||f	           d S )!9Create some temporary objects for slice sorting purposes.Tz.tmpz	pytables-wr   r   zTemporary sortedr   r   r   r   zTemporary indicesr   zTemp chunk boundsr   r   zTemp start boundsr   zTemp end boundsr   r   r   r   zTemporary range valuesrN   r   r   r   z$Temp Last Row sorted values + boundsr   zTemp Last Row indicesN)r\   tempfilemkstempr   r   oscloser   tmpfilerootr   rz   rv   rW   r   r   r   r   r   rQ   r   )	rS   fdr   r  r-  rW   r   r   r   s	            rB   r   zIndex.create_temp  s    
'/K /  /D 	~~d&6<<**3^^,Btz**sHdE!72w	@ 	@ 	@ 	@sIx>>>"GB	A 	A 	A 	A 6b.O$sHdE+>B#8	: 	: 	: 	:sItU,?B5	* 	* 	* 	*sItU,=B5	* 	* 	* 	*sItUOB5	* 	* 	* 	* 	sHdF'b!W	F 	F 	F 	FsItTRE	; 	; 	; 	; a/)+sJe5B5	* 	* 	* 	* sK...-B5	* 	* 	* 	* 	* 	*rD   c           
      l   | j         }| j        }| j        }| j        |f}t	          j        | j                  }| j        }t          |d||d|d|f           t          |dt          | j
                  |d|d|f           |dz
  |z  }| j        |f}t          |d||d	|||f           | j        f}t          |d
||d||f           t          |d||d||f           t          |d||d||f           t          |d|| j        dfd||df           t          |d|| j        fd||f           dS )rS  sorted2zTemporary sorted 2r   rU  indices2r   zTemporary indices 2bounds2zTemp chunk bounds 2abounds2zTemp start bounds 2zbounds2zTemp end bounds 2mbounds2zMedian bounds 2ranges2rN   zTemporary range values 2mranges2zMedian ranges 2N)rz   rv   rW   r   r   r   r   r   r   r   rQ   r   )rS   r  r-  rW   r   r   r   r   s           rB   r  zIndex.create_temp2	  s    ^^,r"tz**hsItU#W!R	B 	B 	B 	BsJ$, ? ? ?$g1b'	C 	C 	C 	C 6b./sItU,AB#8	: 	: 	: 	:sJe-BB5	* 	* 	* 	*sJe-@B5	* 	* 	* 	*sJe->B5	* 	* 	* 	* 	sItdlA%6)7Aw	H 	H 	H 	HsJt|o 're	= 	= 	= 	= 	= 	=rD   c                 l   | j         rt          d           | j        }| j        |z  }| j        }| j        }t          | j                  D ]}|j        |         dd|         	                                }| j        
                    |                    d|j                             | j        
                    |d         |d         gg           | j        
                    ||d|         g           | j        
                    |dd|                    | j        
                    ||dz
  d|                    ||dz  d|         }| j        
                    |           | j        
                    ||dz           g           ~~|j        |         }| j        
                    |                    d|j                             | j        dk    r| j        }	| j        }
| j        }|j        d|         dd|         	                                }t1          |          }||	d|<   t3          j        |dd|         |d         gf          | _        t1          | j                  }| j        |	|||z   <   |j        dd         |
dd<   || _        | j        | j        j        _        | j        | j        j        _        | j         rt          d           d| _        | j                                         tA          | j!                  "                                 d| _!        d| _#        d	| _$        dS )
z>Copy the data and delete the temporaries for sorting purposes.zCopying temporary data...Nr   r   r   rN   zDeleting temporaries...FT)%r  r   r   rz   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r~   r   r   r  r   r   r}   rZ  rY  r   r   unlinkr\   r   )rS   r   r  r  r   r>   r   r  r   r   r   r.  r=  r   r   s                  rB   r  zIndex.cleanup_temp-  s    < 	/-...N	^y(ht|$$ 	B 	BAZ];;Y;/4466FKv~~a==>>>KF2J 78999Krv2v/000Lqu"u...LrAvzrz 2333R1W[b[)GL(((L!2 3444k!nGL7< @ @AAAA q  }HI+K|L[L1++I+>CCEEHx==L&.H]l]#NHTTrTNXb\N+KLLDM$-((G<@MH\,"889=+IaaaL ,D(,(9%)-):&< 	-+,,,T%%''' 
rD   c                    | j         }| j        x}	}
| j        }t          j        | j        |          }t          |          D ]}||z   }||k    r
| j        |z  }
t          |
          D ]]}|||	z  |z            }||	z  }|||	z  z
  |z  }||z  }||z  }||k    r||||z            ||||z   <   F|||||z   f         ||||z   <   ^||k    r|d|
|z           |d|
|z  <   |||<   dS )z)Get sorted & indices values in new order.r   N)rz   r{   r   r   r   rv   r   r~   )rS   newordersrc_disktmp_disklastrowr   r   r   r  r  ncs2self_nslicesr   r>   nsr5  r   insincncs                       rB   get_neworderzIndex.get_neworderk  sT    ^%%d|hT^5999w 	# 	#A!B\!!(B.4[[ 	B 	Bq3w{+SjS3Y",vV,&&&-c#(l&;C27
OO&.sCbL/@&AC27
OO\!!&)*4"9*o

##  #7	# 	#rD   r  c                 6   dddd}| j         }|j        }|j        }|j        }|j        }|j        }|j        }	| j        }
| j        }| j	        }||z  }|}|
                    ||                   }| j        dk    o
| j        dk    }t          | j                  D ]}| j        ||z  z
  }||k     r|}|dk    r n||z  }|||z  ||z  |z            }|| j        dz
  k    r4|r2|dz  }| j        |
z  }t!          j        || j        d|         f          }|                    t(          	          }t+          ||z            }|                     ||||||| j                   |                     ||||	||d
| j        z             |                     d           dS )z/Swap & reorder the different chunks in a block.r   r   r   )r  r  r  rP   r   r   NrT   r!  T)r   )r   r   r   r^  r_  r   r   rz   r{   rw   _f_get_childrQ   r~   r   r   r   r   r  r   argsortdefsortr   rs  r   reorder_slices)rS   rG  boundsnamesr   r   r   
tmp_sortedtmp_indicesr   r   r  r  nsbncbncb2	boundsobjcan_cross_bboundsnblockremainingchunksr   r   ulsbounds_idxr   s                           rB   rC  zIndex.swap_chunks  s    	YH Hh+[
l<M	^Ci$$[%677	!\Q.H43Dq3HDL)) 	E 	EF"lVc\9O$$&qyyckGv|FSL4,??@F$,***% +1&",ss1C(DEE ..g.66K#&&Fk6:x%vtz; ; ;k7K%vut|/CE E E E 	%%%%%rD   c                 L   t          j        ||gt           j                  | _        t          j        |dz   ||j        z   gt           j                  | _        t          j        dt           j                  | _        |                    | j        | j        | j        |           dS )=Read a slice from the `where` dataset and put it in `buffer`.r   rN   r   N)	r   r&  r1   startlr   stoplonesstepl_g_read_slice)rS   r  nslicebufferr  s        rB   
read_slicezIndex.read_slice  s     h	::Xvz56;+>?KK
W1BI666
DKTZHHHHHrD   c                 `   t          j        ||gt           j                  | _        t          j        |dz   ||j        z   gt           j                  | _        t          j        dt           j                  | _        | j        | j        z
  }|                    | j        | j        ||           dS )z>Write a `slice` to the `where` dataset with the `buffer` data.r   rN   r   N)	r   r&  r1   r  r   r  r  r  _g_write_slice)rS   r  r  r  r  countls         rB   write_slicezIndex.write_slice  s     h	::Xvz56;+>?KK
W1BI666
dk)T[$*ffEEEEErD   c                    t          j        |gt           j                  }t          j        ||j        z   gt           j                  }t          j        dgt           j                  }|                    ||||           dS )r  r   r   N)r   r&  r1   r   r  )rS   r  r  r  r  r  r  s          rB   r   zIndex.read_slice_lr  st     5'333%&+-.bi@@@!BI...FE5&99999rD   c                    t          j        |gt           j                  }t          j        ||j        z   gt           j                  }t          j        dgt           j                  }|                    ||||           dS )z>Write a slice from the `where` dataset with the `buffer` data.r   r   N)r   r&  r1   r   r  )rS   r  r  r  r  r  r  s          rB   write_sliceLRzIndex.write_sliceLR  st     5'33356;./ryAAA!BI...VUFF;;;;;rD   c                    | j         }|                     ||||d                    |                     ||||d                    t          j        ||           |                     ||dz
  |d|                    |                     ||dz
  |d|                    |                     |dz
  |d|                    ||d         |d|<   ||d         |d|<   dS )z8Copy & reorder the slice in source to final destination.Nr   )rv   r  r   r   r  r*  )	rS   r  r   r   r:  r;  r{  r|  r-  s	            rB   reorder_slicezIndex.reorder_slice  s     ^
FGBCCL999VXbcc];;; (333!WSbS\:::&1*hssm<<<6A:wss|444rss| "rD   c                 d   | j         }| j        }| j        }|ddg         |j        |<   ||d|         |j        |<   |dd|         |j        ||z  |dz   |z  <   ||dz
  d|         |j        ||z  |dz   |z  <   ||dz  d|         }||j        ||z  |dz   |z  <   ||dz           |j        |<   dS )z%Update the caches for faster lookups.r   r   Nr   rN   )	rz   r{   r   r   r   r   r   r   r   )rS   r  r:  r  r  r   r  s          rB   r*  zIndex.update_caches  s     ^h$aW-
6$RVV_
67>qu"u~FSL&1*!3347>rAvzrz7JFSL&1*!334"'+2+&7>FSL&1*!334%cQh/FrD   c                 
   | j         }|j        }|j        }|r|j        }|j        }n|j        }|j        }| j        }| j        }| j        | j        z  }| j        }	| j	        }
| j
        }t          j        |dz  | j                  }t          j        |dz  t          j        d| j        z                      }| j        dk    r|                     |d|d|                    |                     |d|d|                    d}t!          d|j                  D ]}|                     |||||||           |dk    r| j         j        }| j         j        }|d||z            }||d         }|d||z            }||d         }|                     ||           |                     ||           t-          j        ||           |                     ||           |                     ||           t          j        |dd|         |d         gf          }||||t5          |          z   <   || _        |                     |||d|                    |                     |||d|                    |                     ||d|                    dS t!          |
          D ]}||z  }|                     |||d|                    |                     |||d|                    ||z   }||	k    r|	}|}t!          |dz   |          D ]}|                     |||||||           |                     |||d|                    |                     |||d|                    |                     ||d|                    dS )	an  Reorder completely the index at slice level.

        This method has to maintain the locality of elements in the
        ambit of ``blocks``, i.e. an element of a ``block`` cannot be
        sent to another ``block`` during this reordering.  This is
        *critical* for ``light`` indexes to be able to use this.

        This version of reorder_slices is optimized in that *two*
        complete slices are taken at a time (including the last row
        slice) so as to sort them.  Then, each new slice that is read is
        put at the end of this two-slice buffer, while the previous one
        is moved to the beginning of the buffer.  This is in order to
        better reduce the entropy of the regular part (i.e. all except
        the last row) of the index.

        A secondary effect of this is that it takes at least *twice* of
        memory than a previous version of reorder_slices() that only
        reorders on a slice-by-slice basis.  However, as this is more
        efficient than the old version, one can configure the slicesize
        to be smaller, so the memory consumption is barely similar.

        rN   r   r!  rP   r   Nr   r   )r   r   r   r^  r_  rz   rv   rs   r   r   r~   r   r   r   rQ   r  r   r   r  r   r   r   r   r   r  r  r   r   r  r*  )rS   r   r   r   r{  r|  r  r-  r}  r   r   r.  r:  r;  r  r   r   ssorted2r=  	sindices2	indiceslrr   nbr   lrbs                            rB   ry  zIndex.reorder_slices  s   0 h+ 	&J,KKJ+K^^n.,,'(atz:::8"q&9M0N0NOOO<1 OOJ73B3<888OOKHSbSM:::F6<00 < <""667#*H#-{< < < <
 Q8, H.	"#4B$4#45#BCC=$%6b;&6%67	%bccN	""8X666""9i888 (9===""8X666""9i888>8DDbD>HRL>*JKKDL[3x==%@@A (VVWSbS\:::Wfhssm<<<vwss|44444 Gnn 9 9 Cx
D'#2#,???T8CRC=AAA Sj==!C#D1Hc22 @ @F&&vvw'.'1;@ @ @ @
   ">>>  &(3B3-@@@""673B3<8888+9 9rD   c                    | j         }|j        }|j        }|j        }|j        }| j        }| j        | j        z  }|}	t          | j	                  D ]}
| j
        |
|z  z
  }||k     r|}	|	dk    r d
S |dk    r|j        |
|z  |
|z  |	z   df         }n?|dk    r|j        |
|z  |
|z  |	z   df         }n|dk    r|j        |
|z  |
|z  |	z            }|                    t                    }|t          j        |	          k                                    dz  }|dz  |	k     r| j        rt'          d	|
           |
|	z  }t          |	          D ]}||         }||z   }||z   }||         ||<   ||         ||<   |j        |         |j        |<   |j        |         |j        |<   |j        |         |j        |<   ||z  }|dz   |z  }||z  }|dz   |z  }|j        ||         |j        ||<   |j        ||         |j        ||<   |j        ||         |j        ||<   t          |	          D ]}||z   }||         ||<   ||         ||<   |j        |         |j        |<   |j        |         |j        |<   |j        |         |j        |<   ||z  }|dz   |z  }|j        ||         |j        ||<   |j        ||         |j        ||<   |j        ||         |j        ||<   d
S )zSwap slices in a superblock.r   r  r   r  r  ru  rN   2   z$skipping reordering of superblock ->N)r   r   r   r^  r_  r{   rr   rv   r   r   r   r   r   rw  rx  r   r   sumr  r   rd  re  r   r`  r   ra  r   rb  r   rc  )rS   rG  r   r   r   r{  r|  r  nssnss2sblockremainingslicesr   sranges_idxndiffro  r>   r   oioidxr5  jnxjxjns                           rB   rD  zIndex.swap_sliceso  si    h+[
l!T^3D-.. =	7 =	7F"lVc\9O$$&qyywFSL#1D$Da$GHFSL#1D$Da$GH!!Vc\&3,2E%EF ..g.66K BIdOO388::Q>ErzD   < J@&III$B4[[ 9 9!!n!VCx!'
2")$-B"%*T"2B#&;t#4R "%*T"2BH1f^CZax3&%([C%8QrT"%([C%8QrT"%([C%8QrT""4[[ 7 7!V'^r
)"o!$R
2"%,r"2B!$R
2H1f^$'L2$6AbD!$'L2$6AbD!$'L2$6AbD!!7]=	7 =	7rD   c                    t          |d         |          rt          ||d                   sJ | j        }| j        }| j        }||z  }	|| j        k     rt          |j        |         ||	          }
nt          | j        ||	          dz
  }
|
dk    sJ |
|z  }|| j        k     r.|t          |j	        ||||z   f         |          z  }||k    sJ n5||z   }||k    r|}|t          | j
        ||         |          z  }||k    sJ |dk    sJ |S )z0Search a single item in a specific sorted slice.r   r   )r   r   rz   rv   r~   r   r    r   r   r   r   )rS   r  itemr  limitsr  r  r-  r.  bstartnchunkposends                rB   r)  zIndex.search_item_lt  sJ   
 F1It,,NdF1I1N1NNNN^^'" DL   f!5tVDDFF !f==AF{{{{ rkDL  ;u|FCbL,@A4HHHC"99999(C[  !;t}SW5t<<<C+%%%%Qwwww
rD   c           	      &   | j         }|j        dd         }|j        }|j        }| j        }| j        }	|	dk    rHt          j        | j        d         | j        d         g          }
t          j	        ||
gf          }|dz  }d}d}t          j
        |d          }|                                }|                                }t          |          D ]I}||df         }t          |dz   |          D ]'}||         }||k    sJ ||k    r|| j        k     r|||f         }n||         }||df         }||k    rP|||z
  xx         dz  cc<   || j        k     r||xx         ||z
  z  cc<   |||<   ||xx         |	|z
  z  cc<   |	||<   ||k    r|||z
  xx         dz  cc<   |                     |||||         |          }||z
  }||xx         |z  cc<   |||<   | j        dk    r2|t          ||df                   t          ||df                   z
  z  })K| j        dk    r6t          |d                   t          |d	                   z
  }|dk    r||z  }|r_|d
k    rYt!          d|z  |           t!          d||                                           t!          d||                                           |                                }| j        dk    r)| j                                        r|dk    | j        _        || _        |||fS )a  Compute some statistics about overlaping of slices in index.

        It returns the following info:

        noverlaps : int
            The total number of elements that overlaps in index.
        multiplicity : array of int
            The number of times that a concrete slice overlaps with any other.
        toverlap : float
            An ovelap index: the sum of the values in segment slices that
            overlaps divided by the entire range of values.  This index is only
            computed for numerical types.

        Nr   r   r   r(  r   stringr   r   r   r   initztoverlap (%s):zmultiplicity:
z
overlaps:
rP   )rv   r   r   r   r   r~   r   r&  r   r  r'  r   r   r)  r   floatr   r  rQ   ri   _iswritabler[   r   r   )rS   r  rK  r  r-  r   r   r   r   r.  r/  soverlaptoverlapmultiplicityoverlapsr   r>   r4  r5  r6  r7  r8  r   nelemeranger   s                             rB   compute_overlaps_finegrainz Index.compute_overlaps_finegrain  s     ^aaa>,'??xq!14=3D EFFH^VhZ$899FqLGxgV<<<$$&&""$$w  	N  	NAad|H1q5'** N NQibyyyy"99t|##%af~HH'}H!!Q$<h&& Q'''1,'''4<'' rCx/$&q		 {S'88$/q		(( Q'''1,'''--xF1Is< <C#IEQKKK5(KKK #F1IyH,, !E&A,$7$7%q!t:M:M$MM=NB 9  6%=))E&,,?,??F zz#f, 	;w&(("W,h777#\<3C3C3E3EFFF-8<<>>:::LLNN	<1!9!9!;!;$-NDM "<22rD   c           	      ~   |j         dd         }| j        }| j        dk    rHt          j        | j        d         | j        d         g          }t          j        ||gf          }|dz  }d}d}d}	t          j        |d          }
t          |          D ]}t          |dz   |          D ]m}||df         ||df         k    rU|dz  }|
||z
  xx         dz  cc<   | j	        dk    r2|t          ||df                   t          ||df                   z
  z  }n| j	        dk    r6t          |d                   t          |d	                   z
  }|dk    r||z  }	|r#t          d
|z  ||	           t          |
           | j        dk    r)| j                                        r|dk    | j        _        || _        ||
|	fS )a  Compute some statistics about overlaping of slices in index.

        It returns the following info:

        noverlaps : int
            The total number of slices that overlaps in index.
        multiplicity : array of int
            The number of times that a concrete slice overlaps with any other.
        toverlap : float
            An ovelap index: the sum of the values in segment slices that
            overlaps divided by the entire range of values.  This index is only
            computed for numerical types.

        Nr   r   r   r(  r   r  r  r  zoverlaps (%s):rP   )r   r   r~   r   r&  r   r  r'  r   r   r  r   rQ   ri   r  r[   r   r   )rS   r  rK  r  r   r   r/  r   r  r  r  r>   r5  r  s                 rB   r   zIndex.compute_overlaps8  s     aaa,q  xq!14=3D EFFH^VhZ$899FqLG	xgV<<<w 	N 	NA1q5'** N N!Q$<&A,..NI Q'''1,'''yH,, !E&A,$7$7%q!t:M:M$MMN 9  6%=))E&,,?,??F zz#f, 	 "W,iBBB,<1!9!9!;!;$-NDM "<22rD   c           	         |                      |||          \  }}}||k    rt          j        d| j                  S |dk     r|}| j        |z
  }| j        |z
  }|dk    r-| j        }| j        }t          j        ||z
  | j                  }n/| j        }| j        }t          j        ||z
  d| j	        z            }| j
        }	||	z  }
||	z  }||	z  }||z
  }d}d}t          |
|dz             D ]z}|	|z
  }||z   |k    r||z
  }|dk    r n^|| j        k     r$|                     ||||||z            |           n"|                     |||||z            |           d}||z  }||z  }{|dd|         S )z;Return the sorted or indices values in the specified range.r   r   r   r!  r   N)_process_ranger   r   r   r}   r   r   r   r   rQ   rv   r   r   r  r   )rS   rF  r  r  stepr   valuesvaluesLRbuffer_r-  
nrow_startistart	nrow_stoptlenr  ilenr   blens                     rB   read_sorted_indiceszIndex.read_sorted_indicesv  s   "11%tDDdD==8Atz***!88CNT)E>C'D8[F}Hhte|4:>>>GG\F~Hhte|54<3GHHHG^b[
BJ	e|*i!m44 	 	D;Dd{T!!d{qyydl""D'&$*>"?I I I I ""gfVd]&:;VE E EFdNFDLDDvvvrD   c                 2    |                      d|||          S )zReturn the sorted values of index in the specified range.

        The meaning of the start, stop and step arguments is the same as in
        :meth:`Table.read_sorted`.

        r   r  rS   r  r  r  s       rB   read_sortedzIndex.read_sorted  s     ''%tDDDrD   c                 2    |                      d|||          S )zReturn the indices values of index in the specified range.

        The meaning of the start, stop and step arguments is the same as in
        :meth:`Table.read_sorted`.

        r   r  r  s       rB   read_indiceszIndex.read_indices  s     ''	5$EEErD   c                     ||t          |dz             }|d}nt          |          }|t          | j                  }nt          |          }|d}nt          |          }|||fS )z(Get a range specifc for the index usage.Nr   r   )r   r}   r  s       rB   r  zIndex._process_range  s{     EAI&&D=EEUOOE<DN++DDD>>D<DDD>>DtT""rD   c                 "   t          |          rDt          j        |          }|dk     r
|| j        z  }|                     ||dz   d          d         S t          |t                    r&|                     |j        |j        |j	                  S dS )a  Return the indices values of index in the specified range.

        If key argument is an integer, the corresponding index is returned.  If
        key is a slice, the range of indices determined by it is returned.  A
        negative value of step in slice is supported, meaning that the results
        will be returned in reverse order.

        This method is equivalent to :meth:`Index.read_indices`.

        r   r   N)
r   operatorindexr}   r  
isinstanceslicer  r  r  )rS   keys     rB   __getitem__zIndex.__getitem__  s     #;; 	D.%%CQwwt~%$$S#'155a88U## 	D$$SY#(CCC	D 	DrD   c                     | j         S r^   )r}   rR   s    rB   __len__zIndex.__len__  s
    ~rD   c                 J   | j         j        }| j        | _        t	          |d         |d         d          | j        _        t	          |d         |d         d          | j        _        	 t	          |d         |d         d          | _        	 t	          |d         |d         d	          | _        	 t          j	        | j
        t          j        
          | _        t          j	        | j
        t          j        
          | _        | j                            |            d| _        dS )z;Clean the limits cache and resize starts and lengths arraysBOUNDS_MAX_SLOTSBOUNDS_MAX_SIZEznon-opt types boundsLIMBOUNDS_MAX_SLOTSLIMBOUNDS_MAX_SIZEzbounding limitsSORTEDLR_MAX_SLOTSSORTEDLR_MAX_SIZEzlast row chunksr   FN)ri   paramsr   _sortedr"   boundscachelimboundscachesortedLRcacher   r   r   r,   r   r   _init_sorted_slicer   )rS   r  s     rB   restorecachezIndex.restorecache  s    $ {#.v6H/I/56G/H/E$G $G  #.f5G.H.45F.G.D#F #F	))&1F*G*01E*F*;= = 	+(0D)E)/0C)D):< <	>hTZrx@@@xdjAAA&&t,,,rD   c                 b   t           rt                      }t           rt          d|           | j        r|                                  |r|d         |d         k    rd| j        dd<   d| j        dd<   dS d}| j                            |          }|dk    rJ| j        	                    |          }d| j        dd<   |D ]\  }}}|| j        |<   || j        |<   ||z   } |S | j
        }	| j        dk    rO| j        | j        v r*| j        dk    r |	j        | }n)| j        dk    r |	j        | }n| j        dk    r |	j        | }n| j        dk    r |	j        | }n| j        d	k    r |	j        | }n| j        d
k    r |	j        | }n| j        dk    r |	j        | }n| j        dk    r |	j        | }n| j        dk    r |	j        | }nx| j        dk    r |	j        | }nb| j        dk    r |	j        | }nL| j        dk    r |	j        | }n6| j        dk    r |	j        | }n J d            |                     ||	          }| j        dk    r7|                     |          \  }}
|| j        d<   |
|z
  | j        d<   ||
|z
  z  }| j                                        ryg }t=          | j                  D ].\  }}|dk    r#|                    || j        |         |f           /tA          |          dz  dz  dz   }| j        !                    |||           t           rt          d|           |S )-Do a binary search in this index for an item.zEntering searchr   r   Nr,   r-   float16r2   r3   float96float128r0   r1   r*   r+   r.   r/   FzThis can't happen!r   rP   rN   zExiting search)"r   r   r#   r   r  r   r   r  getslotgetitemr   r   r   r   _search_bin_na_i_search_bin_na_ll_search_bin_na_e_search_bin_na_f_search_bin_na_d_search_bin_na_g_search_bin_na_ui_search_bin_na_ull_search_bin_na_b_search_bin_na_s_search_bin_na_ub_search_bin_na_ussearch_scalarr   search_last_rowcouldenablecacher9   r   r   setitem)rS   r  r   r  nslotstartlengthsnrow2r  lengthr   r  r   r   s                rB   searchzIndex.search  s     	77D 	0($///? 	   	tAwa((DKNDLO1#++D11A::.66u==LDLO(4 % %$uf%*E"&,U#f}K<!yD111 9''262D9DDY'))363T:DDY)++262D9DDY)++262D9DDY)++262D9DDY)++262D9DDY*,,262D9DDY(**363T:DDY(**464d;DDY&((262D9DDY'))262D9DDY'))363T:DDY(**363T:DD6"6666))$77q   0066MUD#DKO#e|DLD5L D//11 	B L )$, 7 7 K KfA:: ''t{4/@&(IJJJ |$$q(1,q0D''lDAAA 	/'...rD   c                     d}t          | j                  D ]:}|                    ||          \  }}|| j        |<   ||z
  | j        |<   |||z
  z  };|S )r  r   )r   r   _search_binr   r   )rS   r  r   r  r>   r  r  s          rB   r  zIndex.search_scalare  sj     t|$$ 	! 	!A"..q$77MUD"DKN"UlDLOD5L DDrD   c                 H   |\  }}| j         }|d         |d         }}|dd         }| j        j        }| j        }	| j        }
| j        | j        z  }d}t          ||          rt          ||          rt          ||          }|	
                    |          }|dk    r|	                    |          }ne||z  }||dz   z  }||
k    r|
}| j                            | j        ||          }|	                    ||                                ||z
  |z             t          ||          }|||z  z  }n|
}nd}t#          ||          rt%          ||          rt'          ||          }||k    r|	
                    |          }|dk    r|	                    |          }ne||z  }||dz   z  }||
k    r|
}| j                            | j        ||          }|	                    ||                                ||z
  |z             t'          ||          }|||z  z  }n|
}nd}||fS )Nr   r   r   )r   r   r   r  r   rz   r   r   r   r    r  r  r   _read_sorted_slicer   r  r   r   r   r!   )rS   r  item1item2r   b0b1r   r   r  hir   r  r  chunkbeginr  r  nchunk2r  s                       rB   r  zIndex.search_last_rowq  s   u=!hrlB!B$:&*^t~5
r"" 	E2&& $VU33%--f55A::)11%88EE&/E$
3CRxx  M<<UC1 1E "))&%**,,+.;(*BD D D#E511f,,Er"" 	E2&& &vu55f$$)11'::Ezz - 5 5e < < *W 4(GaK888"$C $ @ @ K!5 !5
 &--guzz||/2U{h.FH H H#E511
W,,Dt}rD   c                 *   t           rt                      }t           rt          d|           | j        }| j        }| j        }| j        }| j        }| j        |z  }t          j
        | j        |z            }t          j        |d          }	| j        }
| j        dz
  |
z  dz   }| j        | j        z   |
z  }d||dk     <   | j        }t%          | j                  D ]}||         }||         }||k    rt          j        ||z
  d|z            }||k     r|                    ||||           n| j                            |||           |dk    r||z  }n^|dk    r0|                    d	          }t1          ||z  |z            }||z  }n(|dk    r"|                    d	          }||z  |z  }||z  }d
|	|<   | j        }||k    r| j        }t          j
        ||z            }t          j        |d          }||z  }|	                                d         }||z                      d	          }t          j
        |dz   |z                                d	          }t7          ||          D ]\  }}d
|||<   |}	t           rt          d|           |	S )z3Compute a map with the interesting chunks in index.zEntering get_chunkmapr_   r   r   r   r!  rP   rN   r(  TzExiting get_chunkmap)r   r   r#   rv   rw   r   r   rQ   rs   r   r   r}   r   r'  r   r   r   r   r   r   r   _read_index_slicer   r   r   r   rE  zip)rS   r   r-  r}  r   r   rQ   bucketsinblockr   chunkmapr   r   stopsr   r  r  r  r   r   r   r}   tnchunks	tchunkmapratios                           rB   get_chunkmapzIndex.get_chunkmap  s     	77D 	6.555^,,,'1)DNW4558'888N	+/Y.2t|+y8vz,DJ'' 	% 	%F6NE=De||hTE\IIIG##--feT3GGGGN44UD#FFFa<<GOCC\\**V,,C &C->!ABBF6MCC\\**V,,C$rkg5F6MC $(l""Iy\!9::Hxv>>>Il*E""$$Q'CEk))&11FGS1W-..55f==E"6511 - -t(,	%*%% H 	5-t444rD   c                    t          |          dv sJ t          |          dv sJ t          |          t          |          k    sJ | j        }|j        j        }|j        }t          |          dk    r|d         dv sJ |d         }|d         }|dk    r&t          ||d          t          |d||          f}n|dk    rt          ||d          |f}n|d	k    r%t          |d||          t          ||d          f}n|d
k    r|t          ||d          f}n|dk    r||f}nt          |          dk    r|d         dv r
|d         dv sJ |\  }	}
|	|
k    rdS |dk    r%t          |	d||          t          |
d||          f}n@|dk    r|	t          |
d||          f}n%|dk    rt          |	d||          |
f}n
|dk    r|	|
f}|S )N)r   rN   r   r   )ltleeqgegtr"  r   )signr#  r&  r%  r$  rN   )r&  r%  )r"  r#   )r&  r"  )r%  r"  )r&  r#  )r%  r#  )r   ro   r   r   r   r   r
   )rS   opsr  ro   coldtyper   limitoprange_loweruppers              rB   get_lookup_rangezIndex.get_lookup_range  sR   3xx6!!!!6{{f$$$$3xx3v;;&&&&<$$v;;!q6;;;;;1IEQBTzz!(H2>>>#E2xBBDt!(H2>>>!t#E2xBB!(H2>>>@t!(H2>>>@t[[Aq6\))c!f.D.D.D.D!LE5u}}rl""#E2xBB#E2xBBD$$5"h!I!IJ$$#E2xBBEJ$$rD   c                 J    t                                          d           dS )zRemove this Index object.TN)r   	_f_remove)rS   	recursiver   s     rB   r2  zIndex._f_remove#  s#    
 	$rD   c                 ^   g }| j         j        rq| j         j        r|                    d           | j         j        r|                    d           |                    | j         j         d| j         j         d           d| j         d| j         d                    |           d| j	         S )z9This provides a more compact representation than __repr__r(   
bitshufflerA  rB  zIndex(z, z	).is_csi=)
rW   r&   r(   r   r5  r'   r   rT   r;   r   )rS   rW   s     rB   __str__zIndex.__str__*  s     <! 	P|# *y)))|& -|,,,NNdl2NNT\5KNNNOOOI I I9I"ii00I I;?;I I 	JrD   c                    | j         j         d| j        j         }d                    g | j         d| d| j         d| j         d| j         d| j         d| j	         d	| j
         d
| j         d| j         d| j         d| j         d| j        d| j         d| j         d| j         d| j         d| j         d| j                   }|S )z2This provides more metainfo than standard __repr__z.cols.r   z (Index for column z)
  optlevel := z
  kind := z
  filters := z
  is_csi := z
  nelements := z
  chunksize := z
  slicesize := z
  blocksize := z
  superblocksize := z
  dirty := z
  byteorder := z
    sorted := z
    indices := z
    ranges := z
    bounds := z
    sortedLR := z
    indicesLR := )r`   rh   ro   pathnamer;   r   rT   rW   r   r}   rz   rv   rs   rr   r\   r   r   r   r   r   r   r   )rS   	cpathnameretstrs      rB   __repr__zIndex.__repr__8  s5    z-KKT[5IKK	% % % %d& % % % %9 % % % %}% % % %9% % % % l% % % % [	% % % %
 % % % % % % % % % % % % % % % % (% % % % J% % % % % % % % {% % % % % % % % {% % % % {% % % %  !% % % %" .#% % % %$ rD   )
Nr   NNNNr   NNT)Fr^   )r  r   )NNN)C__name__
__module____qualname____doc__
_c_classidpropertyrT   rW   r\   setterro   r`   rt   rw   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r   r  r  rs  rC  r  r  r   r  r  r*  ry  rD  r)  r  r   r  r  r  r  r  r  r  r
  r  r  r   r0  r2  r6  r;  __classcell__)r   s   @rB   rF   rF   Y   sl       1 1f J6 6 X6
   X
 6 6 X6 \	$ 	$ \	$   X   X 5 5 X5 0 0 X0 0 0 X0   X   X 0 0 X0 0 0 X0 , , X, 3 3 X3 8 8 X8 # # X#, ( ( X(
   X0 #% F@ F@ F@ F@ F@ F@PX X X X XtM M M^  (?/ ?/ ?/ ?/B.1 .1 .1 .1`I I I IVnM nM nM`+ + + +Z2* 2* 2*h"= "= "=H< < <|## ## ##J+& +& +& +&ZI I I IF F F F: : : :< < < <& & &$0 0 0"i9 i9 i9VH7 H7 H7 H7T       D[3 [3 [3z<3 <3 <3|( ( (TE E E EF F F F# # #(D D D,       @a a aH
 
 
D D DL: : :x. . .`           J J J      rD   rF   c                       e Zd ZdZd ZdS )IndexesDescGDINDEXc                 J    t          j        d| j        z  t                     d S )Nzthe number of indexed columns on a single description group is exceeding the recommended maximum (%d); be ready to see PyTables asking for *lots* of memory and possibly slow I/Or  r  _v_max_group_widthr   rR   s    rB   _g_width_warningzIndexesDescG._g_width_warningT  7    $ '+&=> 	  	  	  	  	 rD   N)r<  r=  r>  r@  rJ  r(  rD   rB   rE  rE  Q  s(        J         rD   rE  c                       e Zd ZdZed             Zej        d             Zej        d             Zd Zd Z	ed             Z
dS )	IndexesTableGTINDEXc                 :    d| j         vrt          S | j         j        S )N
AUTO_INDEX)r[   default_auto_indexrP  rR   s    rB   autozIndexesTableG.auto`  s     t},,%%}''rD   c                 8    t          |          | j        _        d S r^   )r_   r[   rP  )rS   rR  s     rB   rR  zIndexesTableG.autof  s    #'::   rD   c                     | j         `d S r^   )r[   rP  rR   s    rB   rR  zIndexesTableG.autoj  s    M$$$rD   c                 J    t          j        d| j        z  t                     d S )Nzthe number of indexed columns on a single table is exceeding the recommended maximum (%d); be ready to see PyTables asking for *lots* of memory and possibly slow I/OrH  rR   s    rB   rJ  zIndexesTableG._g_width_warningn  rK  rD   c                 T    |                     d          st          d|z            d S )Nr6   z1names of index groups must start with ``_i_``: %s)r:   
ValueError)rS   r?   s     rB   _g_check_namezIndexesTableG._g_check_namev  s@    u%% 	LCdJL L L	L 	LrD   c                     | j                             d          }|                                dd         }d                    |          }t	          ||          }| j                            |          }|S )zJAccessor for the `Table` object of this `IndexesTableG`
        container.r5   r7   N)rh   r8   r   r;   r   ri   rj   )rS   r=   	tablenameparentpathnamer@   r`   s         rB   r`   zIndexesTableG.table{  sg      &&s++IIKKO	%!.)<<&&}55rD   N)r<  r=  r>  r@  rA  rR  rB  deleterrJ  rX  r`   r(  rD   rB   rM  rM  ]  s        J( ( X(
 
[. . [. 
\% % \%     L L L
   X  rD   rM  c                       e Zd ZdZdZdS )OldIndexz4This is meant to hide indexes of PyTables 1.x files.CINDEXN)r<  r=  r>  r?  r@  r(  rD   rB   r^  r^    s        >>JJJrD   r^  )Jr?  r   r  rX  r   rV  r  pathlibr   timer   r   r   r%  numpyr   idxutilsr   r   r	   r
   r   r   r   r   r   r   r   r   earrayr   carrayr   leafr   indexesr   r   r   groupr   pathr   
exceptionsr   utilsr   r   r   utilsextensionr   r   r   r   r    r!   lrucacheextensionr"   r   r   r   r#   rx  rQ  default_index_filtersdefaultAutoIndexdefaultIndexFiltersr   max32rC   rF   rE  rM  r^  r(  rD   rB   <module>rr     sx   & &   				 



         & & & & & & ) ) ) ) ) )    @ @ @ @ @ @ @ @ @ @ @ @ @ @                                                     9 9 9 9 9 9 9 9 9 9             * * * * * * - - - - - - - - - -8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 + * * * * *
 	 	

 "!!!!!!
 
    !V(,@ @ @  & + * 
 	( ( (u u u u uNE#3#9 u u up?	  	  	  	  	 >5 	  	  	 ' ' ' ' 'NE ' ' 'T    ~u     rD   