I have a data structure and have to perform lookup on it, I would like to optimize things…
struct Data
{
std::string id_;
double data_;
};
I use currently a std::vector<Data> and std::find algorithm but I’m wondering if another data structure would be more convenient :
- hash table ?
- map ?
- boost multi index container ?
- other things ?
EDIT:
Each time I receive a message from network I have to lookup into this vector (with id as key), and update/retrieve some informations. (Data structure have more fields than in my example)
EDIT2:
- I don’t care about order.
- I have to insert/erase element into this data structure frequently.
It really depends on your requirements, but two possibilities are to sort your vector and do a binary search, or to use a map. Both can be implemented within about 15 minutes, so I suggest you try both of them.
Edit: Given your requirement that you want to add and remove things often, and the size of your data, I’d use an
unordered_map(i.e. a hash table) as the first try. You can always change to another container later.