STL-Container:Fast insert/isMember

Started by
1 comment, last by Sharlin 19 years, 6 months ago
Hi! In my program I want to keep track about the fields of the gamemap I have already updated this turn. For this I want to store pointers to each field in an STL container. If the pointer to a field x is not already in the container I do a default update, otherwise I perform a vector addition. Which container would you recommend (insert and isMember are needed)? It sounds like a set, but you never know... Thx!
Advertisement
list? It seems like you travel the whole thing, and only add to the end..
list has a slow (O(n)) membership check. I'd go with set, as both of the required operations are logarithmic. Or, if you don't need to be standard and your STL implementation includes the hash_map extension, use it, as it offers constant-time operations on average.

This topic is closed to new replies.

Advertisement