ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
repKeyVal.m
Go to the documentation of this file.
1%> \brief
2%> Return the input ``hashmap`` with the new ``(key, val)`` appended,
3%> only if the input pair does not exist in the input ``hashmap``.<br>
4%> If the pair exists, replace it with the new value.<br>
5%>
6%> \param[in] key : The input scalar MATLAB string
7%> containing the key to add to the input pair list.
8%> \param[in] val : The input value to be appended to the
9%> input ``hashmap`` after the input ``key``.
10%> \param[in] hashmap : The input cell array of even number of elements
11%> containing the ``(key, val)`` pairs of the ``hashmap``
12%> in sequence as element of the cell array.
13%>
14%> \return
15%> ``hashnew`` : The output cell array of even number of elements
16%> containing the input pair list and ``(key, val)`` pair.<br>
17%> If the input ``key`` exists in the input ``hashmap``,
18%> the input ``(key, val)`` pair will not be added.<br>
19%>
20%> \interface{repKeyVal}
21%> \code{.m}
22%>
23%> hashnew = pm.matlab.hashmap.repKeyVal(key, val, hashmap)
24%>
25%> \endcode
26%>
27%> \example{repKeyVal}
28%> \include{lineno} example/matlab/hashmap/repKeyVal/main.m
29%> \output{repKeyVal}
30%> \include{lineno} example/matlab/hashmap/repKeyVal/main.out.m
31%>
32%> \final{repKeyVal}
33%>
34%> \author
35%> \JoshuaOsborne, May 21 2024, 10:52 PM, University of Texas at Arlington<br>
36%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
37%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
38function hashnew = repKeyVal(key, val, hashmap)
39 hashnew = hashmap;
40 vararginLen = length(hashnew);
41 keyString = string(key);
42 failed = true;
43 for i = 1 : vararginLen - 1
44 try
45 if strcmpi(string(hashnew{i}), keyString)
46 hashnew{i + 1} = val;
47 failed = false;
48 break;
49 end
50 catch
51 continue
52 end
53 end
54 if failed
55 hashnew = {hashnew{:}, key, val};
56 end
57end
function list()
Return a list of MATLAB strings containing the names of OS platforms supported by the ParaMonte MATLA...
function repKeyVal(in key, in val, in hashmap)
Return the input hashmap with the new (key, val) appended, only if the input pair does not exist in t...