def add(self, x, value=1): """ Count element `x` as if had appeared `value` times. By default `value=1` so: sketch.add(x) Effectively counts `x` as occurring once. """ self.n += value for table, i in zip(self.tables, count_min_sketch_hash(x, self.m, self.d)): table[i] += value
def query(self, x): """ Return an estimation of the amount of times `x` has ocurred. The returned value always overestimates the real value. """ return min(table[i] for table, i in zip(self.tables, count_min_sketch_hash(x, self.m, self.d)))