formatting

This commit is contained in:
Jidong Xiao
2023-10-20 10:25:47 -04:00
parent 4ab7ed8f61
commit aac0074adc

View File

@@ -108,12 +108,12 @@ arrays. Arrays and vectors are efficient random access data structures.
++counters[s]; ++counters[s];
``` ```
- For maps, the [] operator searches the map for the pair containing the key (string) s. - For maps, the [] operator searches the map for the pair containing the key (string) s.
If such a pair containing the key is not there, the operator: If such a pair containing the key is not there, the operator:
1. creates a pair containing the key and a default initialized value, 1. creates a pair containing the key and a default initialized value,
2. inserts the pair into the map in the appropriate position, and 2. inserts the pair into the map in the appropriate position, and
3. returns a reference to the value stored in this new pair (the second component of the pair). 3. returns a reference to the value stored in this new pair (the second component of the pair).
This second component may then be changed using operator++. This second component may then be changed using operator++.
If a pair containing the key is there, the operator simply returns a reference to the value in that pair. If a pair containing the key is there, the operator simply returns a reference to the value in that pair.
- In this particular example, the result in either case is that the ++ operator increments the value associated with - In this particular example, the result in either case is that the ++ operator increments the value associated with
string s (to 1 if the string wasnt already it a pair in the map). string s (to 1 if the string wasnt already it a pair in the map).