|
202 | 202 | ## Check type of keys and values, and define numeric_keys
|
203 | 203 | check_types (this);
|
204 | 204 |
|
| 205 | + ## Flatten char keys |
| 206 | + if (! this.numeric_keys) |
| 207 | + keys = cellfun (@(x) x(:).', keys, 'UniformOutput', false); |
| 208 | + endif |
| 209 | + |
205 | 210 | ## Sort keys (faster than call to sort_keys once encoded)
|
206 | 211 | if (this.numeric_keys)
|
207 | 212 | [~, I] = sort (cell2mat (keys));
|
|
261 | 266 | if (! iscell (keySet))
|
262 | 267 | error ("containers.Map: input argument 'keySet' must be a cell");
|
263 | 268 | endif
|
| 269 | + if (! this.numeric_keys) |
| 270 | + ## Flatten char keys |
| 271 | + keySet = cellfun (@(x) x(:).', keySet, 'UniformOutput', false); |
| 272 | + endif |
264 | 273 | enckeySet = encode_keys (this, keySet);
|
265 | 274 | valueSet = cell (size (keySet));
|
266 | 275 | for i = 1:numel (valueSet)
|
|
298 | 307 | in = cellfun ("isnumeric", keySet) | cellfun ("islogical", keySet);
|
299 | 308 | if (! this.numeric_keys)
|
300 | 309 | in = ! in;
|
| 310 | + ## Flatten char keys |
| 311 | + keySet = cellfun (@(x) x(:).', keySet, 'UniformOutput', false); |
301 | 312 | endif
|
302 | 313 | keySet = encode_keys (this, keySet(in));
|
303 | 314 | tf(in) = isfield (this.map, keySet);
|
|
326 | 337 | in = cellfun ("isnumeric", keySet) | cellfun ("islogical", keySet);
|
327 | 338 | if (! this.numeric_keys)
|
328 | 339 | in = ! in;
|
| 340 | + ## Flatten char keys |
| 341 | + keySet = cellfun (@(x) x(:).', keySet, 'UniformOutput', false); |
329 | 342 | endif
|
330 | 343 | keySet = encode_keys (this, keySet(in));
|
331 | 344 | in = isfield (this.map, keySet);
|
|
434 | 447 | || ! isscalar (key))))
|
435 | 448 | error ("containers.Map: specified key type does not match the type of this container");
|
436 | 449 | endif
|
| 450 | + if (ischar (key)) |
| 451 | + key = key(:).'; |
| 452 | + endif |
437 | 453 | enckey = encode_keys (this, key);
|
438 | 454 | if (! isfield (this.map, enckey))
|
439 | 455 | error ("containers.Map: specified key <%s> does not exist",
|
|
473 | 489 | endif
|
474 | 490 | val = feval (this.ValueType, val);
|
475 | 491 | endif
|
| 492 | + if (ischar (key)) |
| 493 | + key = key(:).'; |
| 494 | + endif |
476 | 495 | key = encode_keys (this, key);
|
477 | 496 | if (isfield (this.map, key))
|
478 | 497 | this.map.(key) = val;
|
@@ -652,6 +671,19 @@ function check_types (this)
|
652 | 671 | %! m = containers.Map ('', 3);
|
653 | 672 | %! assert (m(''), 3);
|
654 | 673 |
|
| 674 | +## Test multi-row char array keys |
| 675 | +%!test <*67283> |
| 676 | +%! k1 = char ("key", "one"); |
| 677 | +%! k2 = char ("key", "two"); |
| 678 | +%! k3 = char ("key", "three"); |
| 679 | +%! m = containers.Map ({k1, k2}, {1, 2}); |
| 680 | +%! m(k3) = 3; |
| 681 | +%! assert (m(k1), 1); |
| 682 | +%! assert (m.values ({k1, k3}), {1, 3}); |
| 683 | +%! m.remove ({k1, k3}); |
| 684 | +%! assert (m(k2), 2); |
| 685 | +%! assert (m.isKey ({k1, k2, k3}), [false, true, false]); |
| 686 | +
|
655 | 687 | ## Test numeric keys
|
656 | 688 | %!test
|
657 | 689 | %! key = [1, 2, 3, 4];
|
|
0 commit comments