Crossroads between std :: multimap and std :: vector?

I am looking for an STL container that works like std :: multimap but has constant access time to the random nth element. I need this because I have such a structure in memory that is std :: multimap for many reasons, but the elements stored in it should be presented to the user in a list. Since the amount of data is huge, I use a list box with virtual elements (i.e. list control polls for the value in row X).

As a workaround, I am currently using an additional std :: vector to store the “indices” in std :: map, and I populate it like this:

std::vector<MMap::data_type&> vec;
for (MMap::iterator it = mmap.begin(); it != mmap.end(); ++it)
    vec.push_back((*it).second);

But this is not a very elegant solution.

Is there any such filter?

+3
source share
4 answers

What you need: Increase multi-index

+5
source

How many elements are in this list, what types of elements are and how often do you have to insert or delete them in the middle? Depending on this, it may be convenient for you to use sorted one std::vector<std::pair<key,value>>and use it std::binary_searchwith a search predicate comparing only keys.

+2
source

, , / . , 20 .

, - unordered_multimap? O (1), .

, 2 . , , , .

, , ( O (1)) , B + Tree Radix Tree. , , .

. , :)

+1

hash_multimap. . Hash_multimap - Visual Studio, , GCC . - Boost, .

0
source

Source: https://habr.com/ru/post/1747742/


All Articles