d-_-b
d-_-b

Reputation: 6773

quickest way to get all the unique mapped values in a std::map

I have such a map:

std::map<time_t, int>

There is one value (int) per day (time_t). Some days may have the same value and therefore may not be unique. I need to perform a calculation for each unique int value from this map.

What is the quickest (least CPU usage) way to retrieve them?

Upvotes: 5

Views: 3340

Answers (1)

Guy Adini
Guy Adini

Reputation: 5494

Do you have memory constraints? If not, I would keep an std::set (or whichever hash_set is available in your environment) listing the unique integers.

If you absolutely cannot allocate more memory, maybe you should consider using a different data structure in the first place.

Upvotes: 3

Related Questions