O'Reilly logo

Boost C++ Application Development Cookbook by Antony Polukhin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using an unordered set and map

In the previous recipe, we saw how string comparison can be optimized using hashing. After reading it, the following question may arise, "Can we make a container that will cache hashed values to use faster comparison?".

The answer is yes, and we can do much more. We can achieve almost constant time complexities for search, insertion, and removal of elements.

Getting ready

Basic knowledge of C++ and STL containers is required. Reading the previous recipe will also help.

How to do it...

This will be the simplest of all recipes:

  1. All you need to do is just include the <boost/unordered_map.hpp> header, if we wish to use maps or the <boost/unordered_set.hpp> header, if we wish to use sets.
  2. Now you are free to use boost::unordered_map ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required