Welcome to MorrisCounter’s documentation!

morris_counter package

Submodules

morris_counter.morris_counter module

Module contents

Morris Counter

This package provides Morris Counter, which based on the following paper:

Robert Morris. Counting large numbers of events in small registers. Communications of the ACM, vol. 21, issue 10, pp. 840-842, 1978.

class morris_counter.MorrisCounter(size=1000000, dtype='uint8', radix=2, seed=3282)

Bases: object

count(item)

Compute estimate count value of given item

Parameters

item (str, int, float, and so on.) – interest item

Returns

estimate_value

Return type

int

Examples

>>> mc = MorrisCounter(radix=2, seed=3282)
>>> _ = [mc.increment('ZOC') for _ in range(2000)]
>>> mc.count('ZOC')
2048
>>> _ = [mc.increment(909) for _ in range(2000)]
>>> mc.count(909)
2048
>>> _ = [mc.increment(0.0909) for _ in range(2000)]
>>> mc.count(0.0909)
4096
>>> _ = [mc.increment({}) for _ in range(2000)]
>>> mc.count({})
2048
increment(item)

Increment exponent of given item stochastically

Parameters

item (str, int, float, and so on.) – interest item

Examples

>>> mc = MorrisCounter(radix=2, seed=3282)
>>> _ = [mc.increment('ZOC') for _ in range(2000)]
>>> mc.exponents[mc._get_idx('ZOC')]
11
morris_counter.hashing(item)

Indices and tables