Boost logo

Boost Users :

Subject: [Boost-users] [multi-index] Complex searches, multiple predicates, foreign keys
From: dv (dv_at_[hidden])
Date: 2011-06-07 05:19:50


Hi,

I stumbled upon this multi-index example:
http://www.boost.org/doc/libs/1_46_1/libs/multi_index/doc/examples.html#example6
and I do not understand the gains in the second step.

To sum up, the example wants to apply two predicates to the search -
select elements with the given manufacturer, and select elements that
fall in a certain price range.

It does so by using one predicate in a first search (for example,
finding all elements with the given manufacturer), then taking the range
of search results, and copy it to another multi-index container (using
pointers to avoid unnecessary deep copying of the elements).

Then it performs a second search using the other predicate (in this
example, the price range) to further narrow down the range of results.

It is this copying and creating of the 2nd container that bugs me. Isn't
this unnecessary? It implies O(n) steps to insert the search results, n
being the number of results from the 1st search. Then, why use a second
multi-index container? Why shouldn't I just use remove_copy_if()
instead? it would make sense if copying the subset into a new
multi-index container were faster than O(n), but I doubt that. What do
you think?

regards


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net