How big is the collection for std :: map <k, v> to get ahead of the sorted std :: vector <std :: pair <k, v >>?
How big is the collection for std :: map to get ahead of the sorted std :: vector>?
I have a system in which I need several thousand associative containers, and std::mapit seems to carry a lot of overhead in terms of CPU cache. I heard somewhere that for small collections std :: vector might be faster - but I wonder where this line is ....
EDIT: I am talking about 5 elements or less at a time in a given structure. What interests me most is runtime, not storage space. I know that such questions are inherently platform dependent, but I am looking for a "thumb rule" to use.
Billy3
This is not a matter of size, but use.
A sorted vector works well when the usage pattern is that you read the data and then search the data.
A map works well when a usage pattern includes a more or less arbitrary mixture of modifying data (adding or deleting elements) and querying data.
: ( ). , , O (lg N). , , O (N).
, , , . , , . ( ) . , . / , .
Edit2: ( ). 5 , , , . . , . , ~ 2.5 . log 2 N, ( ) ~ 2.3 - , ( , , ).