@@ -48,10 +48,10 @@ def __init__(self, *invariants):
4848 self ._invariants = _DEFAULT_INVARIANTS
4949 else :
5050 self ._invariants = [_Quantile (q , e ) for (q , e ) in invariants ]
51+
5152 self ._buffer = []
5253 self ._head = None
5354 self ._observations = 0
54- self ._items = 0
5555
5656 def observe (self , value ):
5757 """Samples an observation's value.
@@ -90,7 +90,7 @@ def query(self, rank):
9090 return current ._value
9191
9292 mid_rank = math .floor (rank * self ._observations )
93- max_rank = mid_rank + math .floor (self ._invariant (mid_rank , self ._observations ) / 2 )
93+ max_rank = mid_rank + math .ceil (self ._invariant (mid_rank , self ._observations ) / 2 )
9494
9595 rank = 0.0
9696 while current ._successor :
@@ -115,7 +115,8 @@ def _replace_batch(self):
115115 return
116116
117117 if not self ._head :
118- self ._head , self ._buffer = self ._record (self ._buffer [0 ], 1 , 0 , None ), self ._buffer [1 :]
118+ self ._head = self ._record (self ._buffer [0 ], 1 , 0 , None )
119+ self ._buffer = self ._buffer [1 :]
119120
120121 rank = 0.0
121122 current = self ._head
@@ -136,7 +137,6 @@ def _replace_batch(self):
136137 def _record (self , value , rank , delta , successor ):
137138 """Catalogs a sample."""
138139 self ._observations += 1
139- self ._items += 1
140140
141141 return _Sample (value , rank , delta , successor )
142142
@@ -187,10 +187,10 @@ def __init__(self, quantile, inaccuracy):
187187
188188 """Computes the delta for the observation."""
189189 def _delta (self , rank , n ):
190- if rank <= math .floor (( self ._quantile * n ) ):
190+ if rank <= math .floor (self ._quantile * n ):
191191 return self ._coefficient_i * (n - rank )
192-
193- return self ._coefficient_ii * rank
192+ else :
193+ return self ._coefficient_ii * rank
194194
195195
196196_DEFAULT_INVARIANTS = [_Quantile (0.50 , 0.01 ), _Quantile (0.99 , 0.001 )]
0 commit comments