ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
addKeyVal.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.
4%>
5%> \param[in] key : The input scalar MATLAB string
6%> containing the key to add to the input pair list.
7%>
8%> \param[in] val : The input value to be appended to the
9%> input hashmap after the input ``key``.
10%>
11%> \param[in] hashmap : The input cell array of even number of elements
12%> containing a set of ``(key, val)`` pairs of the hashmap.
13%>
14%> \return
15%> `hashnew` : The output cell array of even number of elements
16%> containing the input pair list and ``(key, val)`` pair.
17%> If the input ``key`` exists in the input ``hashmap``,
18%> the input ``(key, val)`` pair will not be added.
19%>
20%> \interface{addKeyVal}
21%> \code{.m}
22%>
23%> hashnew = pm.matlab.hashmap.addKeyVal(key, val, hashmap)
24%>
25%> \endcode
26%>
27%> \example{addKeyVal}
28%> \include{lineno} example/matlab/hashmap/addKeyVal/main.m
29%> \output{addKeyVal}
30%> \include{lineno} example/matlab/hashmap/addKeyVal/main.out.m
31%>
32%> \final{addKeyVal}
33%>
34%> \author
35%> \JoshuaOsborne, May 21 2024, 10:39 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 = addKeyVal(key, val, hashmap)
39 hashnew = hashmap;
40 if 2 < nargin && 0 < length(hashnew)
41 [currentVal, failed] = pm.matlab.hashmap.getKeyVal(key, hashmap);
42 if failed
43 hashnew = {hashnew{:}, key, val};
44 end
45 else
46 hashnew = {key, val}; % XXX is this correct behavior?
47 end
48end
function list()
Return a list of MATLAB strings containing the names of OS platforms supported by the ParaMonte MATLA...
function addKeyVal(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...