
    uYf                        d dl mZ ddlmZmZmZ ddlmZ d dlZ	 e
 eee	j                  j                  j                  d      d d             Zedk\  r
d dlmc mZ n	d dlmc mZ  G d d	      Z G d
 d      Z G d d      Zy)    )BaseDDSketch   )CubicallyInterpolatedMappingLinearlyInterpolatedMappingLogarithmicMapping)
DenseStoreN.)      r   c                   <    e Zd Zed        Zed        Zed        Zy)KeyMappingProtoc                    t        |      t        u rt        j                  j                  S t        |      t
        u rt        j                  j                  S t        |      t        u rt        j                  j                  S y )N)	typer   pbIndexMappingNONEr   LINEARr   CUBICclsmappings     Q/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/ddsketch/pb/proto.py_proto_interpolationz$KeyMappingProto._proto_interpolation   s^    =..??'''=77??)))=88??((( 9    c                 x    t        j                  |j                  |j                  | j	                  |            S )serialize to protobuf)gammaindexOffsetinterpolation)r   r   r   _offsetr   r   s     r   to_protozKeyMappingProto.to_proto   s1     --227;
 	
r   c                    |j                   t        j                  j                  k(  r*t	        j
                  |j                  |j                        S |j                   t        j                  j                  k(  r*t        j
                  |j                  |j                        S |j                   t        j                  j                  k(  r*t        j
                  |j                  |j                        S t        d|j                   z        )deserialize from protobufzUnrecognized interpolation %r)r   r   r   r   r   from_gamma_offsetr   r   r   r   r   r   
ValueError)r   protos     r   
from_protozKeyMappingProto.from_proto'   s     "//"6"66%77UEVEVWW  BOO$:$::.@@U..    BOO$9$99/AAU..  <u?R?RRSSr   N)__name__
__module____qualname__classmethodr   r!   r'    r   r   r   r      s>    ) ) 
 
 T Tr   r   c                   0    e Zd ZdZed        Zed        Zy)
StoreProtoz"Currently only supports DenseStorec                 X    t        j                  |j                  |j                        S )r   )contiguousBinCountscontiguousBinIndexOffset)r   Storebinsoffset)r   stores     r   r!   zStoreProto.to_proto;   s"     xx %

U\\
 	
r   c                     t               }|j                  }||_        |j                  D ]  }|j	                  ||       |dz  } |S )r#      )r   r1   r4   r0   add)r   r&   r5   indexcounts        r   r'   zStoreProto.from_protoB   sP     .... 	EIIeU#QJE	 r   N)r(   r)   r*   __doc__r+   r!   r'   r,   r   r   r.   r.   8   s+    ,
 
  r   r.   c                   ,    e Zd Zed        Zed        Zy)DDSketchProtoc                     t        j                  t        j                  |j                        t
        j                  |j                        t
        j                  |j                        |j                        S )r   )r   positiveValuesnegativeValues	zeroCount)	r   DDSketchr   r!   _mappingr.   _store_negative_store_zero_count)selfddsketchs     r   r!   zDDSketchProto.to_protoO   sX     {{#,,X->->?%..x?%..x/G/GH**	
 	
r   c                     t         j                  |j                        }t        j                  |j                        }t        j                  |j
                        }|j                  }t        ||||      S )zmdeserialize from protobuf

        N.B., The current protobuf loses any min/max/sum/avg information.
        )r   r5   negative_store
zero_count)r   r'   r   r.   r@   r?   rA   r   )r   r&   r   rJ   r5   rK   s         r   r'   zDDSketchProto.from_protoY   sf     ",,U]];#..u/C/CD%%e&:&:;__
)!	
 	
r   N)r(   r)   r*   r+   r!   r'   r,   r   r   r=   r=   N   s(    
 
 
 
r   r=   )ddsketch.ddsketchr   r   r   r   r   r5   r   google.protobufgoogletuplemapintprotobuf__version__split
pb_versionddsketch.pb.ddsketch_pb2r   ddsketch_pb2ddsketch.pb.ddsketch_pre319_pb2ddsketch_pre319_pb2r   r.   r=   r,   r   r   <module>rZ      s~    * 
   3sFOO77==cB1QGHI
))00!T !TH ,
 
r   