
j\c        
   @@ s  d  Z  d d l m Z d d l m 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
 Z
 d d l m Z 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- m. Z. d d l/ m0 Z0 m1 Z1 m2 Z2 m3 Z3 m4 Z4 m5 Z5 d d l6 m7 Z7 d d l8 Z8 d d l9 m: Z: d Z; e< Z= e< Z> e> rd d l+ m? Z? n  d Z@ eA ZB e  d d d d d eA d e<  ZC eB ZD eC ZE d d d  d! d" d# d$ d% d& d' f
 ZF d( d) ZG d*   ZH e8 jI d+ e e& e jJ f d,     Y ZJ d- e e& f d.     YZK d/ e e& f d0     YZL d1 e e& f d2     YZM d S(3   s    Here is defined the Index class.i    (   t   print_function(   t   absolute_importN(   t   timet   clocki   (   t   calc_chunksizet   calcoptlevelst   get_reduction_levelt	   nextaftert   inftype(   t   indexesextension(   t   NotLoggedMixin(   t   UIntAtomt   Atom(   t   EArray(   t   CArray(   t   Filters(   t
   CacheArrayt   LastRowArrayt
   IndexArray(   t   Group(   t	   join_path(   t   PerformanceWarning(   t   is_idxt   idx2longt   lazyattr(   t   nan_aware_gtt   nan_aware_get   nan_aware_ltt   nan_aware_let   bisect_leftt   bisect_right(   t   ObjectCache(   t   ranges   2.1(   t
   show_statst	   mergesortt	   complevelt   complibt   zlibt   shufflet
   fletcher32t   int8t   int16t   int32t   int64t   uint8t   uint16t   uint32t   uint64t   float32t   float64i   i    c         C@ s   |  j  d  } x- t |  D] \ } } | j d  r Pq q Wd j | |   d | d } d j | | d  } | | f S(   Nt   /t   _i_i   i   (   t   splitt	   enumeratet
   startswitht   join(   t   indexpathnamet   namest   it   namet   tablepathnamet   colpathname(    (    s+   lib/python2.7/site-packages/tables/index.pyt   _table_column_pathname_of_indexc   s    t   Indexc           B@ s  e  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 d@ d d@ d@ d@ d@ d d@ d@ e d 
 Z d   Z d   Z d   Z e d  Z  e d  Z! e d  Z" d   Z# d@ d  Z$ d    Z% d!   Z& d"   Z' d#   Z( d$ d%  Z) d d&  Z* d d'  Z+ d d(  Z, d d)  Z- d*   Z. d+   Z/ d,   Z0 d$ d-  Z1 d d.  Z2 d/   Z3 d0   Z4 d1   Z5 d@ d@ d@ d2  Z6 d@ d@ d@ d3  Z7 d4   Z8 d5   Z9 d6   Z: d7   Z; d8   Z< d9   Z= d:   Z> d;   Z? d<   Z@ e d=  ZA d>   ZB d?   ZC RS(A   s  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).

    t   INDEXc         C@ s'   i d d 6d d 6d d 6d d 6|  j  S(	   s   The kind of this index.t
   ultralighti   t   lighti   t   mediumi   t   fulli   (   t   indsize(   t   self(    (    s+   lib/python2.7/site-packages/tables/index.pyt   kind   s    c         C@ s   |  j  S(   sS   Filter properties for this index - see Filters in
        :ref:`FiltersClassDescr`.(   t
   _v_filters(   RF   (    (    s+   lib/python2.7/site-packages/tables/index.pyt   filters   s    c         C@ s   t  |  j d t  S(   s   Whether the index is dirty or not.
       Dirty indexes are out of sync with column data, so they exist but they
       are not usable.
       t   DIRTY(   t   getattrt   _v_attrst   False(   RF   (    (    s+   lib/python2.7/site-packages/tables/index.pyt   dirty   s    c         C@ sf   |  j  t |  } } | |  j _ |  j j } | rH | rH | j   n  | rb | rb | j   n  d  S(   N(   RN   t   boolRL   RJ   t   tablet   _condition_cachet   nailt   unnail(   RF   RN   t   wasdirtyt   isdirtyt   conditioncache(    (    s+   lib/python2.7/site-packages/tables/index.pyRN      s    c         C@ s=   t  |  j  \ } } |  j j |  } | j j |  } | S(   sQ   The Column (see :ref:`ColumnClassDescr`) instance for the indexed
        column.(   R>   t   _v_pathnamet   _v_filet	   _get_nodet   colst   _g_col(   RF   t	   tablepatht
   columnpathRP   t   column(    (    s+   lib/python2.7/site-packages/tables/index.pyR^      s
    c         C@ s+   t  |  j  \ } } |  j j |  } | S(   s.   Accessor for the `Table` object of this index.(   R>   RW   RX   RY   (   RF   R\   R]   RP   (    (    s+   lib/python2.7/site-packages/tables/index.pyRP      s    c         C@ s   |  j  |  j S(   s%   The number of blocks in a superblock.(   t   superblocksizet	   blocksize(   RF   (    (    s+   lib/python2.7/site-packages/tables/index.pyt   nblockssuperblock   s    c         C@ s   |  j  |  j S(   s    The number of slices in a block.(   R`   t	   slicesize(   RF   (    (    s+   lib/python2.7/site-packages/tables/index.pyt   nslicesblock   s    c         C@ s   |  j  |  j S(   s    The number of chunks in a slice.(   Rb   t	   chunksize(   RF   (    (    s+   lib/python2.7/site-packages/tables/index.pyt   nchunkslice   s    c         C@ sA   |  j  |  j } | |  j } | |  j d k r= | d 7} n  | S(   s)   The total number of superblocks in index.i    i   (   t	   nelementst   nelementsILRR_   R`   (   RF   Rf   t   nblocks(    (    s+   lib/python2.7/site-packages/tables/index.pyt   nsuperblocks   s
    c         C@ sA   |  j  |  j } | |  j } | |  j d k r= | d 7} n  | S(   s$   The total number of blocks in index.i    i   (   Rf   Rg   R`   (   RF   Rf   Rh   (    (    s+   lib/python2.7/site-packages/tables/index.pyRh      s
    c         C@ s   |  j  |  j S(   s'   The number of complete slices in index.(   Rf   Rb   (   RF   (    (    s+   lib/python2.7/site-packages/tables/index.pyt   nslices   s    c         C@ s   |  j  |  j S(   s'   The number of complete chunks in index.(   Rf   Rd   (   RF   (    (    s+   lib/python2.7/site-packages/tables/index.pyt   nchunks  s    c         C@ s   |  j  |  j f S(   s1   The shape of this index (in slices and elements).(   t   nrowsRb   (   RF   (    (    s+   lib/python2.7/site-packages/tables/index.pyt   shape  s    c         C@ s1   |  j  d k o0 |  j d k o0 |  j j |  j k S(   s8   Whether a temporary file for indexes is required or not.i   i    (   RE   t   optlevelRP   Rl   Rb   (   RF   (    (    s+   lib/python2.7/site-packages/tables/index.pyt   temp_required  s    c         C@ s   |  j  d k o |  j d k S(   s@   Whether we should try to build a completely sorted index or not.i   i	   (   RE   Rn   (   RF   (    (    s+   lib/python2.7/site-packages/tables/index.pyt   want_complete_sort  s    c         C@ s_   |  j  d k r t S|  j d k  r& t Sd |  j k r? |  j j S|  j |  d t  |  j d k S(   s   Whether the index is completely sorted or not.

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

        i    i   t   is_csiN(   Rf   RM   RE   RL   Rq   t   compute_overlapst   Nonet	   noverlaps(   RF   (    (    s+   lib/python2.7/site-packages/tables/index.pyRq     s    	
c         C@ s   |  j  j d S(   s0   The number of rows that fits in a *table* chunk.i    (   RP   t
   chunkshape(   RF   (    (    s+   lib/python2.7/site-packages/tables/index.pyt   nrowsinchunk,  s    c         C@ s   t  |  j |  j  } |  j d k re d } |  j | | k r t t j t |  j  |   } q nP |  j d k r d } |  j	 | | k r t t j t |  j	  |   } q n  | S(   s/   Return the length of a bucket based index type.i   i   i   i   i   i   (
   t   minRv   Rd   RE   Rb   t   intt   matht   ceilt   floatR`   (   RF   t   lbuckett   maxnb(    (    s+   lib/python2.7/site-packages/tables/index.pyR|   2  s    ((t    i    c         C@ sd  d  |  _ | |  _ | |  _ |	 |  _ |
 d k r< |
 |  _ n t j |  _ | d  k	 r | j j |  _ | j	 |  _	 i d d 6d d 6d d 6d	 d
 6| } | d k s t
 d   | |  _ n  d  |  _ d  |  _ | |  _ t |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ t |  _ d |  _ d |  _ d d l m } | |  _ t t |   j | | | | |  d  S(   Nt   littlet   bigi   RA   i   RB   i   RC   i   RD   s   indsize should be 1, 2, 4 or 8!ii    (   t	   open_file(   R   R   (   i   i   i   i   (   Rs   t
   _v_versionRn   t   tmp_dirt   expectedrowst	   byteordert   syst   dtypet   baset   typet   AssertionErrorRE   Rl   Rf   t
   blocksizest   Truet
   dirtycacheR_   R`   Rb   Rd   t   tmpfilenamet   opt_search_typesRt   t   tproft   fileR   t	   _openFilet   superR?   t   __init__(   RF   t
   parentnodeR;   t   atomt   titleRG   Rn   RI   R   R   R   R   t   newRE   R   (    (    s+   lib/python2.7/site-packages/tables/index.pyR   J  s<    				#														c         C@ s0  |  j  r t |  _ n  t t |   j   |  j  sn|  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t d   |  j | j d k sAt d   |  j d% k s\t d   | d k rt | j  |  _ t |  j j j  } t |  j j j  } n d |  _ |  j d	 } | } | j |  _ |  j |  j
 | |  _ | |  _ | |  _ | d
 k r|  j d 7_ n  |  j |  j } | d | } | d
 k  rId
 } n  | d 7} |  j | | | !|  _  d  Sd
 |  _ d
 |  _ d
 |  _ d
 |  _ t! j" |  j  }	 |  j# }
 |  j d  k rt% |  j& |  j |  j  |  _ n  |  j \ |  _ |  _	 |  _
 |  _ t' rt( d |  j  n  t) |  j |  j |  j
 |  j  |  _ |  j |  j } |  j
 |  j } t* j+ |  j  |  j _ t* j+ |  j	  |  j _	 t* j, |  j
  |  j _
 t* j, |  j  |  j _ |  j |  j _ |  j |  j _ t- |  d |	 d |
 |  j.  } t- |  d t/ d |  j  d |
 |  j.  t0 |  d |	 d& d |
 |  j& |  j
 d |  j. t1 |  d |	 d' d |
 d |  j. d t2 | d | } t0 |  d |	 d
 | f d |
 |  j3 d | f d |  j. t1 |  d |	 d( d |
 d |  j. d t2 t1 |  d |	 d) d |
 d |  j. d t2 t1 |  d |	 d* d |
 d |  j. d t2 | d | f } t4 |  d |	 | d  |
 | f d |  j. } |  j
 f } t4 |  d! t/ d |  j  | d" |
 |  j f d |  j. } d
 | j _ d
 | j _ d  |  _  t* j5 d# |  j d$ t* j6  |  _7 t* j5 d# |  j d$ t* j6  |  _8 |  j9 r,|  j:   n  d  S(+   Ni   s   Wrong slicesizes   Wrong chunksizei   i   i   s   Wrong indices itemsizes   2.0ii    s   blocksizes:t   sorteds   Sorted Valuest   indicest   itemsizes   Number of chunk in tablet   rangess   Range ValuesR   t   mrangess   Median rangest   _logt   boundss   Boundary Valuest   aboundss   Start boundst   zboundss
   End boundst   mboundss   Median boundst   sortedLRs   Last Row sorted values + boundst	   indicesLRs   Last Row indicesRm   R   (   i   i   i   i   (   i    i   (   i    (   i    (   i    (   i    (;   t   _v_newt	   obversionR   R   R?   t   _g_post_init_hookRL   Rx   R_   R`   Rb   Rd   R   Rn   R   R   R   R   R   R   RE   Rm   R   t   _v_chunkshapet	   reductionR   t   attrsRf   R   Rl   t   nelementsSLRRg   t   beboundsR   t
   from_dtypeRI   Rs   R   R   t   debugt   printR   t   numpyR/   R.   R   R   R   R   R   RM   Rk   R   t   emptyR*   t   startst   lengthsRo   t   create_temp(   RF   t
   idxversionR   R   R   R   Rg   t
   rchunksizet	   nboundsLRR   RI   t
   rslicesizet   nbounds_insliceRm   R   R   (    (    s+   lib/python2.7/site-packages/tables/index.pyR     s    						"				
					!!
		!!	c         C@ s  t  r t   } n  t  r( t d |  n  | j   } |  j } |  j } |  j } t  re t d |  n  | d k r t j d t	 |  d d | | }	 n | d k r t j d t	 |  d d }	 n t j
 t	 |  d	 | d  }	 |  j }
 t |
 | | |
 |
  } d |	 d | +x7 t | | |
  D]# } | |
 d
 |
 |	 | | |
 +q,W| d k r| |  j | |
 } |	 | 7}	 n  | d k r| d k rt	 |  | k st  |  j |  j | |   |  j |  j |	 |   n  t  rt d |  n  t j | |	  | d } | d
 k rt  r4t d |  n  | d d |  j   } t  rct d |  n  | } t  rt d |  qn  | d k rt |  j _ n  t  rt d |  n  | | |	 f S(   s9   Compute an initial indices arrays for data to be indexed.s   Entering initial_appends   Before creating idxi   i    R   R/   i   R.   s   uint%di   i   s   Before keysortis   Before reductionNs   After reductions   After arr <-- reducs   Exiting initial_append(   t   profileR   R!   t   popRE   Rb   Rg   R   t   aranget   lenR   R|   Rx   R    Rc   R   t   read_slice_lrR   R   R	   t   keysortt   copyRM   RL   Rq   (   RF   t   xarrt   nrowR   t   treft   arrRE   Rb   Rg   t   idxR|   t   offsetR:   t   offset2t   larrt   reduc(    (    s+   lib/python2.7/site-packages/tables/index.pyt   initial_append-  sZ    			)! 	!
c         C@ sw   t  r t   } n  t  r( t d |  n  | j d  } | | 7} | |  j } | j d  } t  rs t d |  n  | S(   s+   Perform final operations in 32-bit indices.s   Entering final_idx32R/   R.   s   Exiting final_idx32(   R   R   R!   t   astypeR|   (   RF   R   R   R   (    (    s+   lib/python2.7/site-packages/tables/index.pyt   final_idx32|  s    
c         C@ s  t  r t   } n  t  r( t d |  n  | rJ |  j rJ |  j } d } n |  } |  j } | j } | j } | j } | j	 }	 | j
 }
 | j } | j } | j } | j } | j } | j } |  j | | |  \ } } } | j | j d | j   |  j | } |  j } | j | d | g g  |
 j | | d |  g  | j | d d |   | j | | d d |   | | d d |  } | j |  |	 j | | d g  t  rt d |  n  ~ ~ t  rt d |  n  |  j d k r|  j | | |  j  } n  | j | j d | j   t  rFt d	 |  n  ~ | d |  _ |  j |  j |  _ d |  _ d |  _ |  j | j _ |  j | j _ t |  _ t  rt d
 |  n  d S(   s&   Append the array to the index objects.s   Entering appendi   i    Ni   s   Before deleting arr & smedians   After deleting arr & smediani   s   Before deleting idxs   Exiting append(    R   R   R!   Ro   t   tmpR   R   R   R   R   R   R   R   R   R   R   Rl   R   t   appendt   reshapet   sizeRd   Re   RE   R   Rb   Rf   R   Rg   R   R   R   (   RF   R   t   updateR   t   whereR   R   R   R   R   R   R   R   R   R   R   Rl   R   R   R   t   cst   ncst   smedian(    (    s+   lib/python2.7/site-packages/tables/index.pyR     sf    																		c         C@ s  t  r t   } n  t  r( t d |  n  |  j } | rS |  j rS |  j } d } n |  } |  j } | j } | j } |  j	 | | |  \ }	 }
 } t
 |
  } t
 |  } |  j | } t j |
 d d |  |	 g f  |  _ | | j _ | | j _ t
 |  j  } |  j | | | | +|
 | | *~
 |  j d k rR|  j | | |  j  } n  | | t
 |  *~ | d |  _ | |  j | |  _ | |  _ | |  _ t |  _ t  rt d |  n  d S(   s/   Append the array to the last row index objects.s   Entering appendLRi   Ni   s   Exiting appendLR(   R   R   R!   Rj   Ro   R   R   R   R   R   R   Rd   R   t   concatenateR   R   Rf   RE   R   Rb   Rl   Rg   R   R   R   (   RF   R   R   R   Rl   R   R   R   R   R   R   R   R   Rg   R   R   (    (    s+   lib/python2.7/site-packages/tables/index.pyt   append_last_row  sD    						(
			c         C@ s  |  j  s d S| r t |  _ n	 t |  _ d |  _ d |  _ t |  j |  j |  j	  } | \ } } } } t r} t
 d |  n  |  j   xt r| r0x t |  D] } |  j d d  r Pn  |  j d k r |  j d d  r Pn  |  j d d  r Pq n  |  j d d  rPn  |  j d d	  r Pq q Wn] | rO|  j d d  rOPqOn  | rn|  j d d  rnPqnn  | r|  j d d	  rPqn  Pq W|  j r|  j d k r|  j   n  |  j d k rt j d
 t  qn  |  j   d S(   s   Optimize an index so as to allow faster searches.

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

        Ni    s
   optvalues:t   chunkst   mediani   t   slicest   startt   stops[   OPSI was not able to achieve a completely sorted index.  Please report this to the authors.(   Ro   R   t   verboseR   t
   last_tovert
   last_noverR   Rh   Rn   RE   R   t   create_temp2R    t   swapRp   Rt   t   do_complete_sortt   warningst   warnt   UserWarningt   cleanup_temp(   RF   R   t   optst	   optmediant	   optstartst   optstopst   optfullt   niter(    (    s+   lib/python2.7/site-packages/tables/index.pyt   optimize  sZ    					
		
c   !      C@ s
  |  j  r t   } t   } n  |  j } |  j } | j } |  j } |  j } | d k r t j	 |  j
 d |  j
 d g  } t j | | g f  } | d 7} n  | j }	 | j }
 | j } | j } t j	 g  d |  j } t j	 g  d d |  j } t j d | d t j  } xyt |  D]k} t j	 g  d |  j } t j	 g  d d |  j } | | d f } xVt | d |  D]A} | | } | |  j k  r| | k s~| |  j k r| | k rq~n  | |  j k  r| | k  st d   |	 | | f } n" | | k  st d   | | } | | d f } | | k r| |  j k  rt j | |	 | | d  f f  } t j | |
 | | d  f f  } | | | <q| } t j | | | | !f  } t j | | | | !f  } | | | <q~| | k r~|  j | | | | | |  } | |  j k  rzt j | |	 | | |  f f  } t j | |
 | | |  f f  } n8 t j | | | | !f  } t j | | | | !f  } | | | <q~q~W| |  j k  r-t j | |	 | | | d  f | f  } t j | |
 | | | d  f | f  } nF t j | | | | | !| f  } t j | | | | | !| f  } t j | |  | |  j k  r| |  |	 | <| |  |
 | <|  j | | |   t |  t |  } | | | | !} | | | | !} q t |  } | | k st  d } | | | *| | | *| |  } t j | d d |  j  | d g f  } | | | | t |  +| |  _
 q W| d k st  |  j |  j d	 |  j   |  j  rt t   | d
  } t t   | d
  }  t d | |  f  n  d S(   s>   Bring an already optimized index into a complete sorted state.i    ii   R   s   u%dRm   s3   Two slices cannot overlap completely at this stage!Ns   do_complete_sort()i   s   time: %s. clock: %s(   R   R   R   Rb   R   R   Rj   Rg   R   t   arrayR   R   R   R   R   R   R   RE   t   zerost   int_R    R   t   search_item_ltR	   R   t   update_cachesR   Rd   Rr   t   roundR   (!   RF   t   t1t   c1t   ssR   R   Rj   t   nelementsLRt   rangeslrR   R   R   R   t   sremaint   iremainR   R:   t   sovert   iovert   prev_endt   jt   stjt   next_begt   next_endt   nR   t   ssortedt   sindicest   sendt   sortedlrR   t   tt   c(    (    s+   lib/python2.7/site-packages/tables/index.pyR   M  s    				
		#				
		
%%%(&)


&	c         C@ s  d } d } d } |  j  r0 t   } t   } n  | d k rL |  j |  n | d k rh |  j |  n  | r d | | f } n d | f } |  j |  j | |  j   \ }	 }
 } t |
 j   d  t	 t |
   } |  j  r$t
 t   | d	  } t
 t   | d	  } t d
 | | f  n  | d k r|  j d k r|  j d k r|  j | |  j } |  j |	 |  j } | d k  r| d k  rt Sn  | |  _ |	 |  _ |	 | k  rt S| | k  rt S| d k r| | k  rt St S(   s7   Swap chunks or slices using a certain bounds reference.i(   g?g{Gz?R   R   s   swap_%s(%s)s   swap_%si    i   s   time: %s. clock: %sg        g?(   R   R   R   t   swap_chunkst   swap_slicesRr   R   R   t   nonzeroR{   R   R   R   R   R   RM   (   RF   t   whatt   modet   thnovert   thmultt   thtoverR   R   t   messaget   novert   multt   tovert   rmultR  R  t	   tover_vart	   nover_var(    (    s+   lib/python2.7/site-packages/tables/index.pyR     sD    		&	*		c   	   
   C@ sQ  t  |  _ t j d d |  j  \ } |  _ t j |  |  j |  j d  |  _	 |  j	 j
 |  _ } |  j } |  j } |  j } d | f } t j |  j  } t | d | | d | d d | f t | d	 t d
 |  j  | d | d d | f | d | } d | f } t | d | | d | d | | f d } t | d | | d | d | f t | d | | d | d | f t | d | | d | d | f t | d | d d | d | d f t | d | d  d | d | f | d | f } t | d | | d | d | f | f } t | d t d
 |  j  | d | d | f d S(!   s9   Create some temporary objects for slice sorting purposes.s   .tmps	   pytables-t   wi    R   s   Temporary sortedRu   i   R   R   s   Temporary indicesR   s   Temp chunk boundsR   s   Temp start boundsR   s   Temp end boundsR   s   Median boundsR   i   s   Temporary range valuesR   s   Median rangesR   s$   Temp Last Row sorted values + boundsR   s   Temp Last Row indicesN(   i    (   i    i   (   i    (   R   RN   t   tempfilet   mkstempR   R   t   ost   closeR   t   tmpfilet   rootR   Rd   Rb   RI   R   R   R   R   R   RE   R   (	   RF   t   fdR   R   R   RI   Rm   R   R   (    (    s+   lib/python2.7/site-packages/tables/index.pyR     sN    						c      
   C@ s  |  j  } |  j } |  j } |  j | f } t j |  j  } |  j } t | d | | d | d d | f t | d t	 d |  j
  | d | d d | f | d | } |  j | f } t | d | | d	 | d | | f |  j f } t | d
 | | d | d | f t | d | | d | d | f t | d | | d | d | f t | d | |  j d f d | d | d f t | d | |  j f d | d | f d S(   s9   Create some temporary objects for slice sorting purposes.t   sorted2s   Temporary sorted 2Ru   i   t   indices2R   s   Temporary indices 2t   bounds2s   Temp chunk bounds 2t   abounds2s   Temp start bounds 2t   zbounds2s   Temp end bounds 2t   mbounds2s   Median bounds 2t   ranges2i   s   Temporary range values 2t   mranges2s   Median ranges 2N(   Rd   Rb   RI   Rj   R   R   R   R   R   R   RE   Rk   (   RF   R   R   RI   Rm   R   R   R   (    (    s+   lib/python2.7/site-packages/tables/index.pyR   "  s2    				c         C@ s  |  j  r t d  n  |  j } |  j | } |  j } |  j } xIt |  j  D]8} | j | d d |  j	   } |  j j
 | j d | j   |  j j
 | d | d g g  |  j j
 | | d |  g  |  j j
 | d d |   |  j j
 | | d d |   | | d d |  } |  j j
 |  |  j j
 | | d g  ~ ~ | j | } |  j j
 | j d | j   qN W|  j d k rP|  j }	 |  j }
 |  j } | j |  d d |  j	   } t |  } | |	 | *t j | d d |  | d g f  |  _ t |  j  } |  j |	 | | | +| j |
 (| |  _ n  |  j |  j j _ |  j |  j j _ |  j  rt d  n  d |  _ |  j j    t! j" |  j#  d |  _# t$ |  _% t& |  _' d S(   s>   Copy the data and delete the temporaries for sorting purposes.s   Copying temporary data...Ni   i    ii   s   Deleting temporaries...((   R   R   R   Rd   Re   R   R    Rj   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   Rg   R   R   R   R   R   Rf   Rs   R  R  R  t   removeR   RM   RN   R   R   (   RF   R   R   R   R   R:   R   R   R   R   R   R   R  R   R   (    (    s+   lib/python2.7/site-packages/tables/index.pyR   F  sR    				 ! !#			 
,				c         C@ sS  |  j  } |  j }	 }
 |  j } t j d |  j d |  } xt |  D]} | | } | | k rs |  j | }
 n  x t |
  D] } | | |	 | } | |	 } | | |	 | } | | 7} | | } | | k r | | | | !| | | | +q | | | | |  f | | | | +q W| | k rA| |
 |  | |
 | *qG | | | <qG Wd S(   s)   Get sorted & indices values in new order.Rm   R   N(   Rd   Re   Rj   R   R   Rb   R    Rg   (   RF   t   newordert   src_diskt   tmp_diskt   lastrowRj   R   R   R   R   t   ncs2t   self_nslicesR   R:   t   nsR   R   t   inst   inct   nc(    (    s+   lib/python2.7/site-packages/tables/index.pyt   get_neworder  s(    		



)	R   c      
   C@ s  i d d 6d d 6d d 6} |  j  } | j } | j } | j } | j } | j } | j }	 |  j }
 |  j } |  j	 } | | } | } | j
 | |  } |  j d k o |  j d k } x)t |  j  D]} |  j | | } | | k  r | } n  | d	 k rPn  | | } | | | | | | !} | |  j d	 k rt| rt| d	 7} |  j |
 } t j | |  j |  f  } n  | j d
 t  } t | |  } |  j | | | | | | |  j  |  j | | | |	 | | d |  j  q W|  j d t  d S(   s/   Swap & reorder the different chunks in a block.R   R   R   R   R   R   i   i    i   RG   s   u%dR   N(   R   R   R   R   R!  R   R   Rd   Re   Rc   t   _f_get_childRE   Rg   R    Rh   Rk   R   R   R   t   argsortt   defsortRx   R3  R   t   reorder_slicesR   (   RF   R  t   boundsnamesR   R   R   t
   tmp_sortedt   tmp_indicesR   R   R   R   t   nsbt   ncbt   ncb2t	   boundsobjt   can_cross_bboundst   nblockt   remainingchunksRj   R   t   ult   sbounds_idxR   (    (    s+   lib/python2.7/site-packages/tables/index.pyR	    sH    										
	

c         C@ s   t  j | | g t  j  |  _ t  j | d | | j g t  j  |  _ t  j d d d t  j  |  _ | j |  j |  j |  j |  d S(   s=   Read a slice from the `where` dataset and put it in `buffer`.i   Rm   i   R   N(	   R   R   R/   t   startlR   t   stoplt   onest   steplt   _g_read_slice(   RF   R   t   nslicet   bufferR   (    (    s+   lib/python2.7/site-packages/tables/index.pyt
   read_slice  s
    c         C@ s   t  j | | g t  j  |  _ t  j | d | | j g t  j  |  _ t  j d d d t  j  |  _ |  j |  j } | j |  j |  j | |  d S(   s>   Write a `slice` to the `where` dataset with the `buffer` data.i   Rm   i   R   N(	   R   R   R/   RD  R   RE  RF  RG  t   _g_write_slice(   RF   R   RI  RJ  R   t   countl(    (    s+   lib/python2.7/site-packages/tables/index.pyt   write_slice  s    c         C@ sr   t  j | g d t  j } t  j | | j g d t  j } t  j d g d t  j } | j | | | |  d S(   s=   Read a slice from the `where` dataset and put it in `buffer`.R   i   N(   R   R   R/   R   RH  (   RF   R   RJ  R   RD  RE  RG  (    (    s+   lib/python2.7/site-packages/tables/index.pyR     s    "c         C@ sr   t  j | g d t  j } t  j | | j g d t  j } t  j d g d t  j } | j | | | |  d S(   s>   Write a slice from the `where` dataset with the `buffer` data.R   i   N(   R   R   R/   R   RL  (   RF   R   RJ  R   RD  RM  RG  (    (    s+   lib/python2.7/site-packages/tables/index.pyt   write_sliceLR  s    "c   	      C@ s   |  j  } |  j | | | |  |  j | | | |  t j | |  |  j | | d | |   |  j | | d | |   |  j | d | |   | | | | *| | | | *d S(   s8   Copy & reorder the slice in source to final destination.i   N(   Rb   RK  R	   R   RN  R   (	   RF   RI  R   R   R  R  R9  R:  R   (    (    s+   lib/python2.7/site-packages/tables/index.pyt   reorder_slice  s    	c         C@ s   |  j  } |  j } |  j } | d d g | j | <| | d |  | j | <| d d |  | j | | | d | +| | d d |  | j | | | d | +| | d d |  } | | j | | | d | +| | d | j | <d S(   s%   Update the caches for faster lookups.i    iNi   i   (	   Rd   Re   R   R   R   R   R   R   R   (   RF   RI  R  R   R   R   R   (    (    s+   lib/python2.7/site-packages/tables/index.pyR     s    			)-c      
   C@ s{  |  j  } | j } | j } | r6 | j } | j } n | j } | j } |  j } |  j } |  j |  j } |  j }	 |  j	 }
 |  j
 } t j d | d d |  j  } t j d | d d t j d |  j   } |  j d k r|  j | d | |   |  j | d | |   d } x9 t d | j  D]% } |  j | | | | | | |  q&W| d k r?|  j  j } |  j  j } | | |  } | | } | | |  } | | } |  j | |  |  j | |  t j | |  |  j | |  |  j | |  t j | d d |  | d	 g f  } | | | | t |  +| |  _ n  |  j | | | |   |  j | | | |   |  j | | |   n x t |
  D] } | | } |  j | | | |   |  j | | | |   | | } | |	 k r|	 } n  | } x: t | d |  D]% } |  j | | | | | | |  qW|  j | | | |   |  j | | | |   |  j | | |   qWd S(
   sn  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.

        Rm   i   R   s   u%di   i    i   Ni(   R   R   R   R   R!  Rd   Rb   R`   Rj   Rh   Rg   R   R   R   RE   RK  R    Rl   RP  R   R   R   R	   R   RO  R   R   R   RN  R   (   RF   R   R   R   R9  R:  R   R   R;  Rj   Rh   R   R  R  RI  R   R   t   ssorted2R  t	   sindices2t	   indiceslrR   t   nbR   t   lrb(    (    s+   lib/python2.7/site-packages/tables/index.pyR7     st    											

)

	c         C@ s  |  j  } | j } | j } | j } | j } |  j } |  j |  j } | }	 x4t |  j	  D]#}
 |  j
 |
 | } | | k  r | }	 n  |	 d k r Pn  | d k r | j |
 | |
 | |	  d f } n_ | d k r | j |
 | |
 | |	  d f } n+ | d k r+| j |
 | |
 | |	 !} n  | j d t  } | t j |	  k j   d } | d |	 k  r|  j r\ t d	 |
  q\ q\ n  |
 |	 } xt |	  D] } | | } | | } | | } | | | | <| | | | <| j | | j | <| j | | j | <| j | | j | <| | } | d | } | | } | d | } | j | | !| j | | +| j | | !| j | | +| j | | !| j | | +qWx t |	  D] } | | } | | | | <| | | | <| j | | j | <| j | | j | <| j | | j | <| | } | d | } | j | | !| j | | +| j | | !| j | | +| j | | !| j | | +qWq\ Wd
 S(   s   Swap slices in a superblock.i   R   i    R   R   RG   i   i2   s$   skipping reordering of superblock ->N(   R   R   R   R   R!  Re   R_   Rb   R    Ri   Rj   R   R   R5  R6  R   R   t   sumR   R   R&  R'  R   R"  R   R#  R   R$  R   R%  (   RF   R  R   R   R   R9  R:  R   t   nsst   nss2t   sblockt   remainingslicesR   t   sranges_idxt   ndiffR/  R:   R   t   oit   oidxR   t   jnt   xjt   xjn(    (    s+   lib/python2.7/site-packages/tables/index.pyR
    sn    							((	







c         C@ sc  t  | d |  r& t | | d  s, t  |  j } |  j } |  j } | | }	 | |  j k  r| t | j | | |	  }
 n t |  j	 | |	  d }
 |
 d k s t  |
 | } | |  j k  r | t | j
 | | | |  f |  7} | | k sMt  nN | | } | | k r| } n  | t |  j | | !|  7} | | k sMt  | d k s_t  | S(   s0   Search a single item in a specific sorted slice.i    i   (   R   R   R   Rd   Rb   Rg   Rj   R   R   R   R   R   (   RF   R   t   itemRI  t   limitsR   R   R   R   t   bstartt   nchunkt   post   end(    (    s+   lib/python2.7/site-packages/tables/index.pyR     s(    ,			

*
	c         C@ s}  |  j  } | j } | j } | j } |  j } |  j }	 |	 d k r t j |  j d |  j d g  }
 t j	 | |
 g f  } | d 7} n  d } d } t j
 d | d d  } | j   } | j   } xt |  D]} | | d f } xt | d |  D]} | | } | | k s t  | | k r2q n  | |  j k  rT| | | f } n
 | | } | | d f } | | k r| | | c d 7<| |  j k  r| | c | | 7<| | | <q| | c |	 | 7<|	 | | <q | | k r | | | c d 7<|  j | | | | | |  } | | } | | c | 7<| | | <|  j d	 k r| t | | d f  t | | d f  7} qq q Wq W|  j d	 k rt | d  t | d  } | d k r| | } qn  | r(| d
 k r(t d | |  t d | | j    t d | | j    n  | j   } |  j d k rg|  j j   rg| d k |  j _ n  | |  _ | | | f S(   s  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.

        i    ii   g        g      Rm   R   R   t   stringt   inits   toverlap (%s):s   multiplicity:
s
   overlaps:
i   (   ii   (   i    i    (   Rb   R   R   R   Rj   Rg   R   R   R   R   R   R   R    R   R   R   R{   R   RV  RE   RX   t   _iswritableRL   Rq   Rt   (   RF   R   R  R   R   R   R   R   Rj   R   R   t   soverlapt   toverlapt   multiplicityt   overlapsR   R:   R   R   R   R   R  R   t   nelemt   erangeRt   (    (    s+   lib/python2.7/site-packages/tables/index.pyt   compute_overlaps_finegrain  sn    	
				#



<	c         C@ s  | j  } |  j } |  j d k rj t j |  j d |  j d g  } t j | | g f  } | d 7} n  d } d } d }	 t j d | d d  }
 x t |  D] } x t | d |  D] } | | d f | | d f k r | d 7} |
 | | c d 7<|  j	 d	 k rB| t
 | | d f  t
 | | d f  7} qBq q Wq W|  j	 d	 k rt
 | d  t
 | d  } | d k r| | }	 qn  | rt d
 | | |	  t |
  n  |  j d k r|  j j   r| d k |  j _ n  | |  _ | |
 |	 f S(   s  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.

        i    ii   g        g      Rm   R   R   Rh  s   overlaps (%s):i   (   ii   (   i    i    (   R   Rj   Rg   R   R   R   R   R   R    R   R{   R   RE   RX   Rj  RL   Rq   Rt   (   RF   R   R  R   R   Rj   R   Rt   Rk  Rl  Rm  R:   R   Rp  (    (    s+   lib/python2.7/site-packages/tables/index.pyRr   U  s8    
	# 
<	c         C@ s  |  j  | | |  \ } } } | | k r= t j d |  j  S| d k  rl | } |  j | } |  j | } n  | d k r |  j } |  j } t j | | d |  j } n2 |  j } |  j } t j | | d d |  j	 } |  j
 }	 | |	 }
 | |	 } | |	 } | | } d } d } x t |
 | d  D] } |	 | } | | | k rY| | } n  | d k riPn  | |  j k  r|  j | | | | | | !|  n |  j | | | | | !|  d } | | 7} | | 7} q,W| d d |  S(   s;   Return the sorted or indices values in the specified range.i    R   R   s   u%di   N(   t   _process_rangeR   R   R   Rf   R   R   R   R   RE   Rb   R    Rj   RK  R   (   RF   R  R   R   t   stepR   t   valuest   valuesLRt   buffer_R   t
   nrow_startt   istartt	   nrow_stopt   tlenRd  t   ilenR   t   blen(    (    s+   lib/python2.7/site-packages/tables/index.pyt   read_sorted_indices  sH    				 	





c         C@ s   |  j  d | | |  S(   s   Return 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}  (   RF   R   R   Rs  (    (    s+   lib/python2.7/site-packages/tables/index.pyt   read_sorted  s    c         C@ s   |  j  d | | |  S(   s   Return 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}  (   RF   R   R   Rs  (    (    s+   lib/python2.7/site-packages/tables/index.pyt   read_indices  s    c         C@ s   | d k	 r+ | d k r+ t | d  } n  | d k r@ d } n t |  } | d k rj t |  j  } n t |  } | d k r d } n t |  } | | | f S(   s(   Get a range specifc for the index usage.i   i    N(   Rs   R   Rf   (   RF   R   R   Rs  (    (    s+   lib/python2.7/site-packages/tables/index.pyRr    s    		c         C@ s   t  |  rR t j |  } | d k  r7 | |  j 7} n  |  j | | d d  d St | t  r} |  j | j | j | j	  Sd S(   s  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`.

        i    i   N(
   R   t   operatort   indexRf   R  t
   isinstancet   sliceR   R   Rs  (   RF   t   key(    (    s+   lib/python2.7/site-packages/tables/index.pyt   __getitem__  s    c         C@ s   |  j  S(   N(   Rf   (   RF   (    (    s+   lib/python2.7/site-packages/tables/index.pyt   __len__  s    c         C@ s   |  j  j } |  j |  _ t | d | d d  |  j _ t | d | d d  |  j _ t | d | d d  |  _ t | d | d d	  |  _ t j	 d
 |  j
 d t j  |  _ t j	 d
 |  j
 d t j  |  _ |  j j |   t |  _ d S(   s;   Clean the limits cache and resize starts and lengths arrayst   BOUNDS_MAX_SLOTSt   BOUNDS_MAX_SIZEs   non-opt types boundst   LIMBOUNDS_MAX_SLOTSt   LIMBOUNDS_MAX_SIZEs   bounding limitst   SORTEDLR_MAX_SLOTSt   SORTEDLR_MAX_SIZEs   last row chunksRm   R   N(   RX   t   paramsR   t   _sortedR   t   boundscachet   limboundscachet   sortedLRcacheR   R   Rl   R*   R   R   t   _init_sorted_sliceRM   R   (   RF   R  (    (    s+   lib/python2.7/site-packages/tables/index.pyt   restorecache  s$    



!!c         C@ s	  t  r t   } n  t  r( t d |  n  |  j r> |  j   n  | sY | d | d k rq d |  j (d |  j (d Sd } |  j j |  } | d k r	|  j j	 |  } d |  j (xQ t
 t |   D]= } | | \ } } }	 | |  j | <|	 |  j | <| |	 } q W| S|  j }
 |  j d k r
|  j |  j k r|  j d k rT|
 j |   } q|  j d k ru|
 j |   } q|  j d k r|
 j |   } q|  j d k r|
 j |   } q|  j d k r|
 j |   } q|  j d	 k r|
 j |   } q|  j d
 k r|
 j |   } q|  j d k r;|
 j |   } q|  j d k r\|
 j |   } q|  j d k r}|
 j |   } q|  j d k r|
 j |   } q|  j d k r|
 j |   } q|  j d k r|
 j |   } qt st d   q
|  j | |
  } n  |  j d k r]|  j  |  \ } } | |  j d <| | |  j d <| | | 7} n  |  j j!   rg  } xI t" |  j  D]8 \ } }	 |	 d k r| j# | |  j | |	 f  qqWt |  d d d } |  j j$ | | |  n  t  rt d |  n  | S(   s-   Do a binary search in this index for an item.s   Entering searchi    i   R*   R+   t   float16R0   R1   t   float96t   float128R.   R/   R(   R)   R,   R-   s   This can't happen!ii   i   s   Exiting search(%   R   R   R!   R   R  R   R   R  t   getslott   getitemR    R   R   Rj   R   R   t   _search_bin_na_it   _search_bin_na_llt   _search_bin_na_et   _search_bin_na_ft   _search_bin_na_dt   _search_bin_na_gt   _search_bin_na_uit   _search_bin_na_ullt   _search_bin_na_bt   _search_bin_na_st   _search_bin_na_ubt   _search_bin_na_usRM   R   t   search_scalarR   t   search_last_rowt   couldenablecacheR5   R   t   setitem(   RF   Rb  R   Rz  t   nslott   startlengthsR   t   nrow2R   t   lengthR   R   R   (    (    s+   lib/python2.7/site-packages/tables/index.pyt   search!  s    	


	$c         C@ sh   d } x[ t  |  j  D]J } | j | |  \ } } | |  j | <| | |  j | <| | | 7} q W| S(   s-   Do a binary search in this index for an item.i    (   R    Rj   t   _search_binR   R   (   RF   Rb  R   Rz  R:   R   R   (    (    s+   lib/python2.7/site-packages/tables/index.pyR    s    c         C@ sh  | \ } } |  j  } | d | d } } | d d !} |  j j } |  j }	 |  j }
 |  j |  j } d } t | |  rWt | |  rNt	 | |  } |	 j
 |  } | d k r |	 j |  } ni | | } | | d } | |
 k r |
 } n  |  j j |  j | |  } |	 j | | j   | | |  t	 | |  } | | | 7} q]|
 } n d } t | |  rXt | |  rOt | |  } | | k r/|	 j
 |  } | d k r|	 j |  } q/| | } | | d } | |
 k r|
 } n  |  j j |  j | |  } |	 j | | j   | | |  n  t | |  } | | | 7} q^|
 } n d } | | f S(   Ni    ii   (   R   R   R   R  R   Rd   R   R   R   R   R  R  R   t   _read_sorted_sliceR   R  R   R   R   R   (   RF   Rb  t   item1t   item2R   t   b0t   b1R   R   R  t   hiR   Re  R  t   chunkt   beginRg  R   t   nchunk2R   (    (    s+   lib/python2.7/site-packages/tables/index.pyR    s^    			
			
			c         C@ s  t  r t   } n  t  r( t d |  n  |  j } |  j } |  j } |  j } |  j } t |  j	  | } t
 t j t |  j  |   } t j d | d d  }	 |  j }
 |  j d |
 d } |  j |  j |
 } d | | d k  <|  j } x*t |  j  D]} | | } | | } | | k r t j d | | d d |  } | | k  rh| j | | | |  n |  j j | | |  | d k r| | } nr | d	 k r| j d
  } t
 | | |  } | | 7} n6 | d k r	| j d
  } | | | } | | 7} n  t |	 | <q q W|  j } | | k r|  j } t
 t j t |  |   } t j d | d d  } t |  | } |	 j   d } | | j d
  } t j | d |  j d
  } x/ t t |   D] } t | | | | | +qW| }	 n  t  rt d |  n  |	 S(   s3   Compute a map with the interesting chunks in index.s   Entering get_chunkmapRm   R   RO   i   i    s   u%di   i   R   s   Exiting get_chunkmap(   R   R   R!   Rb   Rc   Rj   R|   RE   R{   R`   Rx   Ry   Rz   Rf   R   R   R   R   R   R   R    Rl   R   t   _read_index_sliceR   R   R   Rv   R  R   (   RF   R   R   R;  Rj   R|   RE   t   bucketsinblockRk   t   chunkmapR   R   t   stopsR   RI  R   R   R   R   Rv   Rf   t   tnchunkst	   tchunkmapt   ratioR:   (    (    s+   lib/python2.7/site-packages/tables/index.pyt   get_chunkmap  sf    					"		

 		 	c         C@ s  t  |  d k s t  t  |  d k s0 t  t  |  t  |  k sN t  |  j } | j j } | j } t  |  d k r| d d k s t  | d } | d } | d k r t | | d	 d
 t | d
 | |  f } q| d k rt | | d	 d
 | f } q| d k rFt | d 
| |  t | | d	 d 
f } q| d k rq| t | | d	 d 
f } q| d k r| | f } qnt  |  d k r| d d k r| d d k st  | \ }	 }
 |	 |
 k rd S| d k rt |	 d 
| |  t |
 d
 | |  f } q| d k rG|	 t |
 d
 | |  f } q| d k rrt |	 d 
| |  |
 f } q| d k r|	 |
 f } qn  | S(   Ni   i   i    t   ltt   let   eqt   get   gtt   signi(   i   i   (   i   i   (   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   (   RF   t   opsRc  R^   t   coldtypeR   t   limitt   opt   range_t   lowert   upper(    (    s+   lib/python2.7/site-packages/tables/index.pyt   get_lookup_range  sN    		

&c         C@ s   t  t |   j t  d S(   s   Remove this Index object.N(   R   R?   t	   _f_removeR   (   RF   t	   recursive(    (    s+   lib/python2.7/site-packages/tables/index.pyR  F  s    c         C@ s   d } |  j  j rg |  j  j r+ | d 7} n  |  j  j rD | d 7} n  | d |  j  j |  j  j f 7} n  d |  j |  j | |  j f S(   s9   This provides a more compact representation than __repr__R~   s	   , shuffles   , bitshuffles   , %s(%s)s   Index(%s, %s%s).is_csi=%s(   RI   R#   R&   t
   bitshuffleR$   Rn   RG   Rq   (   RF   RI   (    (    s+   lib/python2.7/site-packages/tables/index.pyt   __str__M  s    c         C@ s   |  j  j d |  j j } d |  j | |  j |  j |  j |  j |  j |  j	 |  j
 |  j |  j |  j |  j f } | d |  j 7} | d |  j 7} | d |  j 7} | d |  j 7} | d |  j 7} | d |  j 7} | S(	   s2   This provides more metainfo than standard __repr__s   .cols.s   %s (Index for column %s)
  optlevel := %s
  kind := %s
  filters := %s
  is_csi := %s
  nelements := %s
  chunksize := %s
  slicesize := %s
  blocksize := %s
  superblocksize := %s
  dirty := %s
  byteorder := %rs   
  sorted := %ss   
  indices := %ss   
  ranges := %ss   
  bounds := %ss   
  sortedLR := %ss   
  indicesLR := %s(   RP   RW   R^   t   pathnameRn   RG   RI   Rq   Rf   Rd   Rb   R`   R_   RN   R   R   R   R   R   R   R   (   RF   t	   cpathnamet   retstr(    (    s+   lib/python2.7/site-packages/tables/index.pyt   __repr__\  s    N(D   t   __name__t
   __module__t   __doc__t
   _c_classidt   propertyRG   RI   RN   t   setterR^   RP   Ra   Rc   Re   Ri   Rh   Rj   Rk   Rm   Ro   Rp   Rq   R   Rv   R|   Rs   R   R   R   R   R   RM   R   R   R   R   R   R   R   R   R3  R	  RK  RN  R   RO  RP  R   R7  R
  R   Rq  Rr   R}  R~  R  Rr  R  R  R  R  R  R  R  R  R  R  R  (    (    (    s+   lib/python2.7/site-packages/tables/index.pyR?   m   s   3


?		O	A1K	r/	4	$	>	%-
					lJ"	]	>	*				 	e		G	<	1	t   IndexesDescGc           B@ s   e  Z d  Z d   Z RS(   t   DINDEXc         C@ s   t  j d |  j t  d  S(   Ns   the 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   t   _v_max_group_widthR   (   RF   (    (    s+   lib/python2.7/site-packages/tables/index.pyt   _g_width_warning  s    (   R  R  R  R  (    (    (    s+   lib/python2.7/site-packages/tables/index.pyR  {  s   t   IndexesTableGc           B@ sb   e  Z d  Z e d    Z e j d    Z e j d    Z d   Z d   Z e d    Z	 RS(   t   TINDEXc         C@ s   d |  j  k r t S|  j  j S(   Nt
   AUTO_INDEX(   RL   t   default_auto_indexR  (   RF   (    (    s+   lib/python2.7/site-packages/tables/index.pyt   auto  s    c         C@ s   t  |  |  j _ d  S(   N(   RO   RL   R  (   RF   R  (    (    s+   lib/python2.7/site-packages/tables/index.pyR    s    c         C@ s   |  j  ` d  S(   N(   RL   R  (   RF   (    (    s+   lib/python2.7/site-packages/tables/index.pyR    s    c         C@ s   t  j d |  j t  d  S(   Ns   the 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/O(   R   R   R  R   (   RF   (    (    s+   lib/python2.7/site-packages/tables/index.pyR    s    c         C@ s&   | j  d  s" t d |   n  d  S(   NR3   s1   names of index groups must start with ``_i_``: %s(   R6   t
   ValueError(   RF   R;   (    (    s+   lib/python2.7/site-packages/tables/index.pyt   _g_check_name  s    c         C@ sV   |  j  j d  } | j   d } d j |  } t | |  } |  j j |  } | S(   sB   Accessor for the `Table` object of this `IndexesTableG` container.R2   i   (   RW   R4   R   R7   R   RX   RY   (   RF   R9   t	   tablenamet   parentpathnameR<   RP   (    (    s+   lib/python2.7/site-packages/tables/index.pyRP     s    (
   R  R  R  R  R  R  t   deleterR  R  RP   (    (    (    s+   lib/python2.7/site-packages/tables/index.pyR    s   			t   OldIndexc           B@ s   e  Z d  Z d Z RS(   s4   This is meant to hide indexes of PyTables 1.x files.t   CINDEX(   R  R  R  R  (    (    (    s+   lib/python2.7/site-packages/tables/index.pyR    s   (N   R  t
   __future__R    R   Ry   R  R  t   os.pathR   R  R   R   R   R   t   idxutilsR   R   R   R   R   R~   R	   t   nodeR
   R   R   R   t   earrayR   t   carrayR   t   leafR   t   indexesR   R   R   t   groupR   t   pathR   t
   exceptionsR   t   utilsR   R   R   t   utilsextensionR   R   R   R   R   R   t   lrucacheextensionR   t   sixt	   six.movesR    R   RM   R   R   R!   R6  R   R  t   default_index_filterst   defaultAutoIndext   defaultIndexFiltersR   t   max32R>   t   python_2_unicode_compatibleR?   R  R  R  (    (    (    s+   lib/python2.7/site-packages/tables/index.pyt   <module>   sp   (.
	
	        ,