ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
repKeyVal.m File Reference

Go to the source code of this file.

Functions

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 the input hashmap.
If the pair exists, replace it with the new value.
More...
 

Function Documentation

◆ repKeyVal()

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 the input hashmap.
If the pair exists, replace it with the new value.

Parameters
[in]key: The input scalar MATLAB string containing the key to add to the input pair list.
[in]val: The input value to be appended to the input hashmap after the input key.
[in]hashmap: The input cell array of even number of elements containing the (key, val) pairs of the hashmap in sequence as element of the cell array.
Returns
hashnew : The output cell array of even number of elements containing the input pair list and (key, val) pair.
If the input key exists in the input hashmap, the input (key, val) pair will not be added.


Possible calling interfaces

hashnew = pm.matlab.hashmap.repKeyVal(key, val, hashmap)


Example usage

1cd(fileparts(mfilename('fullpath'))); % Change working directory to source code directory.
2addpath('../../../../'); % Add the ParaMonte library root directory to the search path.
3
4pm.matlab.show()
5pm.matlab.show('hashmap = {"key1", 1, "key2", "val2"};')
6 hashmap = {"key1", 1, "key2", "val2"};
7
8pm.matlab.show()
9pm.matlab.show('hashnew = pm.matlab.hashmap.repKeyVal("key2", 2, hashmap);')
10 hashnew = pm.matlab.hashmap.repKeyVal("key2", 2, hashmap);
11pm.matlab.show('hashnew')
12pm.matlab.show( hashnew )
13
14pm.matlab.show()
15pm.matlab.show('hashnew = pm.matlab.hashmap.repKeyVal("key3", true, hashmap);')
16 hashnew = pm.matlab.hashmap.repKeyVal("key3", true, hashmap);
17pm.matlab.show('hashnew')
18pm.matlab.show( hashnew )
19
20pm.matlab.show()
21pm.matlab.show('hashnew = pm.matlab.hashmap.repKeyVal("key3", false, hashmap);')
22 hashnew = pm.matlab.hashmap.repKeyVal("key3", false, hashmap);
23pm.matlab.show('hashnew')
24pm.matlab.show( hashnew )
function root()
Return a scalar MATLAB string containing the root directory of the ParaMonte library package.

Example output
1
2hashmap = {"key1", 1, "key2", "val2"};
3
4hashnew = pm.matlab.hashmap.repKeyVal("key2", 2, hashmap);
5hashnew
6hashnew{1}
7key1
8hashnew{2}
9 1
10hashnew{3}
11key2
12hashnew{4}
13 2
14
15hashnew = pm.matlab.hashmap.repKeyVal("key3", true, hashmap);
16hashnew
17hashnew{1}
18key1
19hashnew{2}
20 1
21hashnew{3}
22key2
23hashnew{4}
24val2
25hashnew{5}
26key3
27hashnew{6}
28 1
29
30hashnew = pm.matlab.hashmap.repKeyVal("key3", false, hashmap);
31hashnew
32hashnew{1}
33key1
34hashnew{2}
35 1
36hashnew{3}
37key2
38hashnew{4}
39val2
40hashnew{5}
41key3
42hashnew{6}
43 0


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Joshua Alexander Osborne, May 21 2024, 10:52 PM, University of Texas at Arlington
Fatemeh Bagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.
Amir Shahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin