How to compute moving unique item Imaging I am running a forum and I continuously have log in of members. A member can log in simultaneously many times

So I have :

Tom Jerry Jack Tom Joe Kay Neo Tom ...


each log in comes with a time stamp

I want to have an algorithm that can count how many UNIQUE names have logged in the past 1 minute.

How to design an algorithm like this?

My design is to use a std::map then continuously update/trim the map

I am wondering if there is any smarter solution here.

Any insight?
Keep a hash table that stores a histogram of the items that have appeared in the past minute, as well as a counter for the number of unique items, initialized at zero. Also keep a circular queue with the actual timestamped list of items.

Every time you see a new item or query the number of unique items, go over the circular queue and delete all items which are older than one minute. For each one that you delete, update the histogram. If a cell in the histogram reaches zero, decrement the unique items counter, and delete the cell. If you are adding a new item, update the histogram, and if the item did not appear in the hash table, increase the unique items counter.