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

Go to the source code of this file.

Functions

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 the input hashmap. More...
 

Function Documentation

◆ addKeyVal()

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 the input hashmap.

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 a set of (key, val) pairs of the hashmap.
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.addKeyVal(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.addKeyVal("key3", false, {});')
10 hashnew = pm.matlab.hashmap.addKeyVal("key3", false, {});
11pm.matlab.show('hashnew')
12pm.matlab.show( hashnew )
13
14pm.matlab.show()
15pm.matlab.show('hashnew = pm.matlab.hashmap.addKeyVal("key2", "val2", hashmap);')
16 hashnew = pm.matlab.hashmap.addKeyVal("key2", "val2", hashmap);
17pm.matlab.show('hashnew')
18pm.matlab.show( hashnew )
19assert(all([hashnew{:}] == [hashmap{:}]))
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.addKeyVal("key3", false, {});
5hashnew
6hashnew{1}
7key3
8hashnew{2}
9 0
10
11hashnew = pm.matlab.hashmap.addKeyVal("key2", "val2", hashmap);
12hashnew
13hashnew{1}
14key1
15hashnew{2}
16 1
17hashnew{3}
18key2
19hashnew{4}
20val2


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:39 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