Boost multi_index: retrieves unique non-unique key values

I have boost::multi_index_container, whose elements are such structures:

struct Elem {
    A a;
    B b;
    C c;
};

The main key (in the sense of a database) is composite_key aand b. Others there are keys for performing various types of queries.

Now I need to get a set of all different values c. These values โ€‹โ€‹are certainly unique, but repeating through all the records (albeit ordered), or the use std::uniqueseems rather a waste, given that it is expected that the number of different values cwill be <than the total number of records (for example, from 10 to 1000).

Am I missing an easy way to get this result more efficiently?

+3
source share
1

Boost.MultiIndex , . , .

, , , std::map<C, size_t> ( -) multi_index_container "".

C (). C. , Elem multi_index_container, . Elem multi_index_counter, . , .

C, <key,value> key . std::map, C .

C ( ), . , C std::set<C>, C.

, C , C. std::set<C> , C a std::vector, , std::unique.

, , unique. N - C, M - C. , , O (N * log (M)). M N, O (N). , + O (N * log (N)).

+1

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


All Articles