map / multimap depth exploration

map / multimap rb_tree likewise as the underlying structure, the same elements of automatic sorting characteristics, a basis for sorting key.

We can not change the key value of map / multimap by the iterator, this is not because rb_tree not allowed, but the map / multimap be modified by using the key value in const define your own data types of the time.

 

 There are four template parameter map, and wherein the default parameters Campare Alloc the same set, and the alloc are less, can be seen from FIG green box, so that the key pair using the map data bundled with the value_type become their own, at the same time with the const the modified their key values.

 

 

 map and multimap differ when inserting, at the beginning of the study, multimap is the key and value their insertion (insert function through line 53 codes are visible ), while the map is carried out by [] assignment ( Code 53 line ), we already know, map the bottom is implemented by rb_tree, so use [] array assignment is certainly not the same as the address assignment, where [] is overloaded symbols.

 

 Translation Blue Note: Returns the data associated with the key specified in the index. If the key does not exist, create the key using the default values, and then return.

That is, when found key exists, return data associated with the key, or the creation and returns a pointer to the key iterator to key in the most appropriate position.

 

Guess you like

Origin www.cnblogs.com/area-h-p/p/12335600.html