shaikh - 6 months ago 31

C++ Question

What is the best way to store multi-dimensional data in C++?

I am looking for some dynamic data structure rather than static multi-dimensional arrays, as the number of elements to be stored in the structure can not be pre-determined.

Additionally, I am looking for a data structure that can minimize the memory cost and provide faster lookup. Is there any ready made data structure or I must implement some multi-dimensional tree-based data structure?

Edit: I have to store multi-dimensional stream data in some data structure. E.g., the data stream is of the form: (key1, key2, key3, value1), (key1, key2, key3, value2), (key1, key2, key3, value3), ...

Later I would like to search the data with respect to different keys.

Answer

I have to store multi-dimensional stream data in some data structure. E.g., the data stream is of the form: (key1, key2, key3, value), (key1, key2, key3, value), (key1, key2, key3, value), ...

Later I would like to search the data with respect to different keys.

`boost::multiindex`

allows to add different kinds of indices to your container.

It's a pretty complex library and can be a bit painful to get used to it. But that's worth the trouble, because the problem it solves is a pretty common one.