MCPcopy Create free account
hub / github.com/nodejs/node / Histogram

Class Histogram

deps/v8/tools/eval_gc_nvp.py:50–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48
49
50class Histogram:
51 def __init__(self, bucket_trait, fill_empty):
52 self.histogram = {}
53 self.fill_empty = fill_empty
54 self.bucket_trait = bucket_trait
55
56 def add(self, key):
57 index = self.bucket_trait.value_to_bucket(key)
58 if index not in self.histogram:
59 self.histogram[index] = 0
60 self.histogram[index] += 1
61
62 def __str__(self):
63 ret = []
64 keys = self.histogram.keys()
65 keys.sort()
66 last = keys[len(keys) - 1]
67 for i in range(0, last + 1):
68 (min_value, max_value) = self.bucket_trait.bucket_to_range(i)
69 if i == keys[0]:
70 keys.pop(0)
71 ret.append(" [{0},{1}[: {2}".format(
72 str(min_value), str(max_value), self.histogram[i]))
73 else:
74 if self.fill_empty:
75 ret.append(" [{0},{1}[: {2}".format(
76 str(min_value), str(max_value), 0))
77 return "\n".join(ret)
78
79
80class Category:

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected