1919See the License for the specific language governing permissions and
2020limitations under the License.
2121'''
22+ from __future__ import division
23+ from builtins import range
24+ from builtins import object
2225import math
2326import sys
2427from hdrh .iterators import AllValuesIterator
@@ -32,7 +35,7 @@ def get_bucket_count(value, subb_count, unit_mag):
3235 smallest_untrackable_value = subb_count << unit_mag
3336 buckets_needed = 1
3437 while smallest_untrackable_value <= value :
35- if smallest_untrackable_value > sys .maxint / 2 :
38+ if smallest_untrackable_value > sys .maxsize / / 2 :
3639 return buckets_needed + 1
3740 smallest_untrackable_value <<= 1
3841 buckets_needed += 1
@@ -96,22 +99,20 @@ def __init__(self,
9699 self .lowest_trackable_value = lowest_trackable_value
97100 self .highest_trackable_value = highest_trackable_value
98101 self .significant_figures = significant_figures
99- self .unit_magnitude = int (math .floor (math .log (lowest_trackable_value ) /
100- math .log (2 )))
102+ self .unit_magnitude = int (math .floor (math .log (lowest_trackable_value ) / math .log (2 )))
101103 largest_value_single_unit_res = 2 * math .pow (10 , significant_figures )
102- subb_count_mag = int (math .ceil (math .log (largest_value_single_unit_res ) /
103- math .log (2 )))
104+ subb_count_mag = int (math .ceil (math .log (largest_value_single_unit_res ) / math .log (2 )))
104105 self .sub_bucket_half_count_magnitude = subb_count_mag - 1 if subb_count_mag > 1 else 0
105106 self .sub_bucket_count = int (math .pow (2 , self .sub_bucket_half_count_magnitude + 1 ))
106- self .sub_bucket_half_count = self .sub_bucket_count / 2
107+ self .sub_bucket_half_count = self .sub_bucket_count // 2
107108 self .sub_bucket_mask = (self .sub_bucket_count - 1 ) << self .unit_magnitude
108109 self .bucket_count = get_bucket_count (highest_trackable_value ,
109110 self .sub_bucket_count ,
110111 self .unit_magnitude )
111- self .min_value = sys .maxint
112+ self .min_value = sys .maxsize
112113 self .max_value = 0
113114 self .total_count = 0
114- self .counts_len = (self .bucket_count + 1 ) * (self .sub_bucket_count / 2 )
115+ self .counts_len = (self .bucket_count + 1 ) * (self .sub_bucket_count // 2 )
115116 self .word_size = word_size
116117
117118 if hdr_payload :
@@ -273,7 +274,7 @@ def get_value_at_percentile(self, percentile):
273274 '''
274275 count_at_percentile = self .get_target_count_at_percentile (percentile )
275276 total = 0
276- for index in xrange (self .counts_len ):
277+ for index in range (self .counts_len ):
277278 total += self .get_count_at_index (index )
278279 if total >= count_at_percentile :
279280 value_at_index = self .get_value_from_index (index )
@@ -299,7 +300,7 @@ def get_percentile_to_value_dict(self, percentile_list):
299300 percentile_list = list (set (percentile_list ))
300301 percentile_list .sort ()
301302
302- for index in xrange (self .counts_len ):
303+ for index in range (self .counts_len ):
303304 total += self .get_count_at_index (index )
304305 while True :
305306 # recalculate target based on next requested percentile
@@ -347,8 +348,8 @@ def get_max_value(self):
347348 def get_min_value (self ):
348349 if 0 < self .counts [0 ] or self .total_count == 0 :
349350 return 0
350- if sys .maxint == self .min_value :
351- return sys .maxint
351+ if sys .maxsize == self .min_value :
352+ return sys .maxsize
352353 return self .get_lowest_equivalent_value (self .min_value )
353354
354355 def _hdr_size_of_equiv_value_range (self , value ):
@@ -384,10 +385,10 @@ def get_stddev(self):
384385 def reset (self ):
385386 '''Reset the histogram to a pristine state
386387 '''
387- for index in xrange (self .counts_len ):
388+ for index in range (self .counts_len ):
388389 self .counts [index ] = 0
389390 self .total_count = 0
390- self .min_value = sys .maxint
391+ self .min_value = sys .maxsize
391392 self .max_value = 0
392393
393394 def __iter__ (self ):
@@ -513,7 +514,7 @@ def add(self, other_hist):
513514 else :
514515 # Arrays are not a direct match, so we can't just stream through and add them.
515516 # Instead, go through the array and add each non-zero value found at it's proper value:
516- for index in xrange (other_hist .counts_len ):
517+ for index in range (other_hist .counts_len ):
517518 other_count = other_hist .get_count_at_index (index )
518519 if other_count > 0 :
519520 self .record_value (other_hist .get_value_from_index (index ), other_count )
0 commit comments