Re: Question about boost::multi_index emplace operations
Joaquin M López Muñoz via Boost-users <[email protected]>
| Newsgroups | gmane.comp.lib.boost.user |
|---|---|
| Message-ID | <[email protected]> |
El 03/11/2022 a las 8:06, Pavel Vazharov escribió: > On Wed, Nov 2, 2022 at 10:05 PM Joaquin M López Muñoz > <[email protected]> wrote: > > Insert+modify works fine as far as I can see: > [...] > > Your particular problem hints at the more general issue that > Boost.MultiIndex indices do not have > something like try_emplace, which is the semantics you're after. > The reason why this function > is not available is that we have set-like indices, not map-like > indices. > [...] > > > Hi, > > Thanks for the response. > > Yes, you are right, I'm looking for an API with semantics like > try_emplace and now > I understand the complications for it for the case of boost multi_index. > > I'm currently using emplace + modify API. My initial question was not > very clear about this. > However, my understanding is that the modify call will try to > reposition the node because > it can't be sure if the user callback hasn't changed something in the > entry which would > require repositioning of the node in any of the indices. > Is my understanding of the modify API correct? > As I'm using hashed + sequenced indices, I know that setting only the > mapped_type > in the modify call won't cause any repositioning in the both of the > above indices. > Thus I was trying to avoid the additional work which happens > internally in the modify call. modify repositions the element after the modifier is called, but *only* if necessary: in the interest of performance, a pre-check is done for each index, and if the element remains in place no further work is done. This in-place check is faster than actually re-positioning the element: https://github.com/boostorg/multi_index/blob/develop/include/boost/multi_index/hashed_index.hpp#L1578-L1589 To sum up, there's some overhead even if your modifier does not touch keys, but not has high as actually reinserting the element. > BTW, thanks for working on boost::unordered_flat_map because it'll > allow us to remove > 3rd party dependency from our projects as we are currently using > https://greg7mdp.github.io/parallel-hashmap/. Glad to hear about that! It'd be great if you could download the upcoming beta and provide early feedback before Boost 1.81 ships. Joaquín M López Muñoz _______________________________________________ Boost-users mailing list [email protected] https://lists.boost.org/mailman/listinfo.cgi/boost-users