Home > Back-end >  Help bosses (map)
Help bosses (map)

Time:10-01

Why use map than with a long long one dimensional array of time-consuming
Just pay a problem, just change the map to the array, take from 2 s to 0.12 s

When should also use the map is ok (I only know that in a set of number n, when n is particularly big, can't use a one-dimensional array need to use) grateful!!

CodePudding user response:

No can not use ah, you say is the STL map a map? This is a class, with the mapping, affirmation is slower than the separate use Numbers, if digital particularly big, dynamically allocated array, if the dynamic distribution, then crashed,

CodePudding user response:

Because the map is different from the structure of the array, a tree map layer structure, for example, defines a sequence of a, you want to visit a [10000], array size first address directly 10000 *, one can access to, and the map to search again, when using a map? Cannot use arrays in map, the keys of the map if it is a positive integer, of course it is better to use an array

CodePudding user response:

refer to the second floor Italink response:
because the map is different from the structure of the array, a tree map layer structure, for example, defines a sequence of a, are you going to visit a [10000], array size first address directly 10000 *, one can access to, and the map to search again, when using a map? Cannot use arrays in map, map keys if it is a positive integer, of course, it is better to use array

Whoa oww, I see, thank you

CodePudding user response:

Before you do any other questions, classmate say if array is especially big in map, so met a bigger I will directly use the map??????

CodePudding user response:

Map, hash_map, mainly for fast, if often find, don't have to,
Don't I a little more, about two-thirds hash_map faster than map lookup,

CodePudding user response:

reference 5 floor GKatHere reply:
map, hash_map, mainly for fast, if often find, don't have to,
Don't I a little bit more, hash_map around two-thirds faster than map lookup,

Whoa oww, good dalai dalai, thank you!
  • Related