The fastest way to speed up the map display is <string, int> .find () in C ++. Where keys are in alphabetical order

I have a card with approximately 100,000 pairs. Is there a way to speed up the search when using find () if the keys are in alphabetical order. Just like I should do it. I know that when creating a map you can specify a new comparator. But will this speed up the find () function?

Thanks in advance.

[resolved] Thanks to the guys in the group, I decided to go with the vector and use the bottom and top to “crop” some of the searches.

I'm also new here, is there a way to mark this question in response or choose the best answer?

+5
source share
4 answers

, ( ).

, , , std::vector std::lower_bound std::upper_bound.

, , std::unordered_map .

: : , " " " " , . , , , , () , , , .

+11

std::map , - . , (, ).

unordered_map (aka hash_map pre ++ 11? O (1) O (log (n)) std::map.

, trie, , , , unordered_map .

+4

std::find , map::find ( .) map::find , .

, -, unordered_map, map.

+4

unordered_map, .

, , . , , . , , .

Going Native 2012 Bjarne Stroustroup , . vector list , , , list , - vector . , 43.

unordered_map , , , , vector (, , , vector), ,

+2
source

All Articles