Frequency Counting Algorithms Over Data Streams
micvog.com
micvog.com
This 2002 paper describes a data structure for this that I suspect is superior to what is described in the article: https://www.cs.rutgers.edu/~farach/pubs/FrequentStream.pdf
A good statistic for this is an exponentially weighted moving average, which can be computed online by a leaky integrator using a single accumulator register per counted entity.
It's not so much as counting, as estimating a rate.
That requires O(n) memory space, where n is the number of counted entities. If you're willing to spend this much memory, the problem is easy. Algorithms like the one in the article (or the paper I mentioned) are for when you want to use far less memory than that.
E.g., Where the frequency counting algorithms might estimate the following counts for a given stream: A: 2, B: 5, C:1 ...HyperLogLog would estimate that you have three types of events (A, B and C but you only get the count: 3) in it. Presumably, HyperLogLog requires fewer time and space resources to achieve this more summarized perspective.