ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
getKeyVal.m
Go to the documentation of this file.
1%> \brief
2%> Return the value corresponding to the input ``key``
3%> in the input ``hashmap`` cell array.
4%>
5%> \param[in] key : The input scalar MATLAB string
6%> containing the key to search for in the input pair list.
7%>
8%> \param[in] hashmap : The input cell array of even number of elements
9%> containing the ``(key, val)`` pairs of the hashmap
10%> in sequence as element of the cell array.
11%>
12%> \return
13%> ``val`` : The output MATLAB object stored in the element of the
14%> input cell array, whose ``key`` is given as the input.
15%> <br>
16%> ``failed`` : The output scalar MATLAB logical that is ``true``
17%> if and only if the input ``key`` exists in the input ``hashmap``,
18%> otherwise, it is ``false``.<br>
19%> (**optional**. If missing, ``val`` will remain an empty array ``[]`` on output.)
20%>
21%> \interface{getKeyVal}
22%> \code{.m}
23%>
24%> val = pm.matlab.hashmap.getKeyVal(key, hashmap)
25%> [val, failed] = pm.matlab.hashmap.getKeyVal(key, hashmap)
26%>
27%> \endcode
28%>
29%> \warning
30%> The length of the input ``hashmap`` must be even.<br>
31%> Ann odd length of the input cell array will lead to a runtime call to the MATLAB intrinsic ``error()``.<br>
32%>
33%> \example{getKeyVal}
34%> \include{lineno} example/matlab/hashmap/getKeyVal/main.m
35%> \output{getKeyVal}
36%> \include{lineno} example/matlab/hashmap/getKeyVal/main.out.m
37%>
38%> \final{getKeyVal}
39%>
40%> \author
41%> \JoshuaOsborne, May 21 2024, 10:43 PM, University of Texas at Arlington<br>
42%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
43%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
44function [val, failed] = getKeyVal(key, hashmap)
45 vararginLen = length(hashmap);
46 if mod(vararginLen, 2) ~= 0
47 help("pm.matlab.hashmap.getKeyVal");
48 error ( newline ...
49 + "The length of ``hashmap`` must be even." + newline ...
50 + newline ...
51 + "length(hashmap) = " + string(vararginLen) + newline ...
52 + newline ...
53 );
54 end
55 val = [];
56 if 1 < nargout
57 failed = true;
58 end
59 for i = 1 : vararginLen - 1
60 if strcmpi(string(hashmap{i}), string(key))
61 if 1 < nargout
62 failed = false;
63 end
64 val = hashmap{i + 1};
65 return;
66 end
67 end
68end
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.