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

+3
source share
5 answers

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 - , ( , , ).

+9

"", ( ), , ( - , - , ). , .

( ), ( ). ( ).

: ! , , . http://www.cplusplus.com/reference/stl/

+1

std::map - , .

: Loki::AssocVector.

AssocVector , , , , - . AssocVector . ( ).

...

, , , : Allocator , , , ( ).

, : ?

++ STL- Sorted Associative Containers . ++ 0x unordered_map, !

+1

: , 5 :

. std:: map, . , , .


, .


, - , , :

  • , ?
  • ?
  • ? , , - .

  • , ? std:: map .
  • /?
  • ? (32/64 )
  • std::vector? ( 1,5 2).

, , , , , .

0

. ...

. , , , . , .

, < > . ( ), , , , .

, , , CPU, .

, .

: , , , 5 .

0

Source: https://habr.com/ru/post/1748543/


All Articles