Boost logo

Boost Users :

Subject: [Boost-users] Can Boot MultiIndex help me?
From: Paolo Bolzoni (paolo.bolzoni.brown_at_[hidden])
Date: 2015-07-22 09:31:00


Dear list,

I needed a data structure such that:
- a list of POD structs (with an Id and other fields) stays in
contiguous memory. This is required because I need to pass this block
of memory to a C function.
- the order of this POD structs is irrelevant.
- I need to access to each element from the Id quickly.

So I implemented a class using std::map and std::vector; the vector
contains the structs and the map associate between the ids and the
vector position.
The vector ensures C memory layout and the map gives the elements from
the Id quickly.

To delete an element I copy the last element in its position, update
the map, and pop the vector back (of course there are some special
cases, like deleting the last element... but you got the point)
To add an element I push it back to the vector and update the map.

It works fine, but a colleague mentioned that boost multiindex can do
a similar job. I checked the documentation, but I am not sure I can
build an index on a vector. Is that possible? Thanks.

Your faithfully,
Paolo


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