1cd(fileparts(mfilename(
'fullpath'))); % Change working directory to source code directory.
2addpath(
'../../../../'); % Add the ParaMonte library
root directory to the search path.
5pm.matlab.show(
'hashmap = {"key1", 1, "key2", "val2", "key3", false};')
6 hashmap = {
"key1", 1,
"key2",
"val2",
"key3",
false};
9pm.matlab.show(
'[val, failed] = pm.matlab.hashmap.getKeyVal("key2", hashmap);')
10 [val, failed] = pm.matlab.hashmap.getKeyVal(
"key2", hashmap);
13pm.matlab.show(
'failed')
14pm.matlab.show( failed )
15assert(val ==
"val2" && ~failed)
18pm.matlab.show(
'[val, failed] = pm.matlab.hashmap.getKeyVal("key3", hashmap);')
19 [val, failed] = pm.matlab.hashmap.getKeyVal(
"key3", hashmap);
22pm.matlab.show(
'failed')
23pm.matlab.show( failed )
24assert(val ==
false && ~failed)
27pm.matlab.show(
'[val, failed] = pm.matlab.hashmap.getKeyVal("key3", hashmap(1:4));')
28 [val, failed] = pm.matlab.hashmap.getKeyVal(
"key3", hashmap(1:4));
31pm.matlab.show(
'failed')
32pm.matlab.show( failed )
33assert(isempty(val) && failed)
36pm.matlab.show(
'[val, failed] = pm.matlab.hashmap.getKeyVal("key2", hashmap(1:4));')
37 [val, failed] = pm.matlab.hashmap.getKeyVal(
"key2", hashmap(1:4));
40pm.matlab.show(
'failed')
41pm.matlab.show( failed )
42assert(val ==
"val2" && ~failed)
45pm.matlab.show(
'try; pm.matlab.hashmap.getKeyVal("key2", hashmap(1:3)); catch me; disp(string(me.identifier) + string(me.message)); end')
46 try; pm.matlab.hashmap.getKeyVal(
"key2", hashmap(1:3));
catch me; disp(
string(me.identifier) +
string(me.message)); end
function root()
Return a scalar MATLAB string containing the root directory of the ParaMonte library package.
2hashmap = {
"key1", 1,
"key2",
"val2",
"key3",
false};
4[val, failed] = pm.matlab.hashmap.getKeyVal(
"key2", hashmap);
12[val, failed] = pm.matlab.hashmap.getKeyVal(
"key3", hashmap);
20[val, failed] = pm.matlab.hashmap.getKeyVal(
"key3", hashmap(1:4));
27[val, failed] = pm.matlab.hashmap.getKeyVal(
"key2", hashmap(1:4));
35try; pm.matlab.hashmap.getKeyVal(
"key2", hashmap(1:3));
catch me; disp(
string(me.identifier) +
string(me.message)); end
37 > Return the value corresponding to the input ``key``
38 > in the input ``hashmap`` cell array.
40 > \param[in] key : The input scalar MATLAB
string
41 > containing the key to search
for in the input pair
list.
43 > \param[in] hashmap : The input cell array of even number of elements
44 > containing the ``(key, val)`` pairs of the hashmap
45 > in sequence as element of the cell array.
48 > ``val`` : The output MATLAB
object stored in the element of the
49 > input cell array, whose ``key`` is given as the input.
51 > ``failed`` : The output scalar MATLAB logical that is ``
true``
52 >
if and only
if the input ``key`` exists in the input ``hashmap``,
53 > otherwise, it is ``
false``.<br>
54 > (**optional**. If missing, ``val`` will remain an empty array ``[]`` on output.)
59 > val = pm.matlab.hashmap.getKeyVal(key, hashmap)
60 > [val, failed] = pm.matlab.hashmap.getKeyVal(key, hashmap)
65 > The length of the input ``hashmap`` must be even.<br>
66 > Ann odd length of the input cell array will lead to a runtime call to the MATLAB intrinsic ``error()``.<br>
69 > \include{lineno} example/matlab/hashmap/
getKeyVal/main.m
71 > \include{lineno} example/matlab/hashmap/
getKeyVal/main.out.m
76 > \JoshuaOsborne, May 21 2024, 10:43 PM, University of Texas at Arlington<br>
77 > \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
78 > \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
81The length of ``hashmap`` must be even.
function list()
Return a list of MATLAB strings containing the names of OS platforms supported by the ParaMonte MATLA...
function getKeyVal(in key, in hashmap)
Return the value corresponding to the input key in the input hashmap cell array.