Updating containers.Map with a new containers.Map - does new key overwrite old?
조회 수: 2 (최근 30일)
이전 댓글 표시
A new containers.Map can be created by combining two containers.Map:
m1 = containers.Map({1, 5, 8}, {'A', 'B', 'C'});
m2 = containers.Map({8, 9, 6}, {'X', 'Y', 'Z'});
m = [m1; m2];
keys(m), values(m)
ans =
[1] [5] [6] [8] [9]
ans =
'A' 'B' 'Z' 'X' 'Y'
Note that value 'C' for key 8 was overwritten. In the same way I could update Map m1 with the key/value pairs in m2:
m1 = [m1; m2];
keys(m1), values(m1)
ans =
[1] [5] [6] [8] [9]
ans =
'A' 'B' 'Z' 'X' 'Y'
What I would like to know (the documentation isn't clear on this) is:
Is it guaranteed that the value in m2 will overwrite any duplicate key values from m1.
I could take the question a step further with this example:
m1 = containers.Map({1, 5, 8}, {'A', 'B', 'C'});
m2 = containers.Map({8, 9, 6}, {'X', 'Y', 'Z'});
m3 = containers.Map({2, 8, 3}, {'Q', 'R', 'S'});
m1 = [m1; m2; m3];
keys(m1), values(m1)
ans =
[1] [2] [3] [5] [6] [8] [9]
ans =
'A' 'Q' 'S' 'B' 'Z' 'R' 'Y'
It seems that the last appearing value for the key 8 becomes the new value. But is that guaranteed, and will it always be that way in the future?
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!