Boost logo

Boost :

Subject: [boost] Boost MultiIndex slow mass insertion
From: miticodonati_at_[hidden]
Date: 2017-04-27 09:38:18

I have the following structure:

typedef boost::multi_index_container<
        boost::multi_index::hashed_unique<boost::multi_index::member<MyClass, int, &amp;MyClass::label>>,
        boost::multi_index::ordered_non_unique<boost::multi_index::member<MyClass, double, &amp;MyClass::dist>>
> MyClassSet;

If i populate it in a loop:

MyClassSet all:
for (int y = 0; y < input.rows; ++y) {
    MyClass c;
    // ....

the insertion time is quite slow. It probably need to continuously re-order the underlying implementation.
Anyway i would expect that populating it with a single call it would be faster (e.g. sorting the whole set only at the end).

std::vector<MyClass> vec;
// ...
MyClassSet all(vec.begin(), vec.end());

BUT... the times are almost equal.

My question is: is this intended behaviour?
Is there a faster way to mass populate the container (e.g. not enforcing the invariants/orderings at each 'insert')?

Boost list run by bdawes at, gregod at, cpdaniel at, john at