How is the C++ multimap container implemented?

user656925 picture user656925 · Jun 6, 2011 · Viewed 14k times · Source

For example a C++ vector is implemented using a dynamic array where each element uses consecutive memory spaces.

I know that a C++ multimap is a one to many relationship but what is the internal structure?

Answer

Magnus Hoff picture Magnus Hoff · Jun 6, 2011

The C++ standard does not define how the standard containers should be implemented, it only gives certain constraints like the one you say for vectors.

multimaps have certain runtime complexity (O(lg n) for the interesting operations) and other guarantees, and can be implemented as red-black trees. This is how they are implemented in the GNU standard C++ library.