I need a container that can quickly find over 1 million items and keep the insertion order.
So, at first I thought about std :: map, but he does not care about the insert order, which he orders the data according to the key. I found boost :: multi_index which should preserve the insertion order and quickly search for data through an indexed field (which is id (and not unique!) For my case). So I did something like this:
struct myData { unsigned long id; unsigned long insertionOrder; myData (){}; myData (unsigned long id_,unsigned long insertionOrder_):id(id_), insertionOrder(insertionOrder _)){} ~ myData (){}; }; typedef multi_index_container< myData, indexed_by< random_access<>,
I can put data in a container without any problems. Suppose I insert 5 elements into my container, for example:
myDataContainer.push_back(myData(1002, 1)); myDataContainer.push_back(myData(1001, 2)); myDataContainer.push_back(myData(1005, 3)); myDataContainer.push_back(myData(1003, 4)); myDataContainer.push_back(myData(1000, 5));
The problem is that I search in the container for the element "1001" iterator++ returns "1002" , and iteratorโ returns "1000" . Thus, it seems that he does not care about the insertion order and orders the data according to the indexed value.
I expect results for iterator++ : "1002" and for iterator-- : "1005" . I mean the data according to the insertion order.
Am I doing something wrong? How can I achieve something like a quick index search and returning data according to the insertion order.
I am working on Visual Studio 2008, Visual C ++, Win 7 x64.
c ++ boost search containers boost-multi-index
user2955554
source share