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

Go to the source code of this file.

Functions

function getKeyVal (in key, in hashmap)
 Return the value corresponding to the input key in the input hashmap cell array. More...
 

Function Documentation

◆ getKeyVal()

function getKeyVal ( in  key,
in  hashmap 
)

Return the value corresponding to the input key in the input hashmap cell array.

Parameters
[in]key: The input scalar MATLAB string containing the key to search for in the input pair list.
[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
val : The output MATLAB object stored in the element of the input cell array, whose key is given as the input.
failed : The output scalar MATLAB logical that is true if and only if the input key exists in the input hashmap, otherwise, it is false.
(optional. If missing, val will remain an empty array [] on output.)


Possible calling interfaces

val = pm.matlab.hashmap.getKeyVal(key, hashmap)
[val, failed] = pm.matlab.hashmap.getKeyVal(key, hashmap)
Warning
The length of the input hashmap must be even.
Ann odd length of the input cell array will lead to a runtime call to the MATLAB intrinsic error().


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", "key3", false};')
6 hashmap = {"key1", 1, "key2", "val2", "key3", false};
7
8pm.matlab.show()
9pm.matlab.show('[val, failed] = pm.matlab.hashmap.getKeyVal("key2", hashmap);')
10 [val, failed] = pm.matlab.hashmap.getKeyVal("key2", hashmap);
11pm.matlab.show('val')
12pm.matlab.show( val )
13pm.matlab.show('failed')
14pm.matlab.show( failed )
15assert(val == "val2" && ~failed)
16
17pm.matlab.show()
18pm.matlab.show('[val, failed] = pm.matlab.hashmap.getKeyVal("key3", hashmap);')
19 [val, failed] = pm.matlab.hashmap.getKeyVal("key3", hashmap);
20pm.matlab.show('val')
21pm.matlab.show( val )
22pm.matlab.show('failed')
23pm.matlab.show( failed )
24assert(val == false && ~failed)
25
26pm.matlab.show()
27pm.matlab.show('[val, failed] = pm.matlab.hashmap.getKeyVal("key3", hashmap(1:4));')
28 [val, failed] = pm.matlab.hashmap.getKeyVal("key3", hashmap(1:4));
29pm.matlab.show('val')
30pm.matlab.show( val )
31pm.matlab.show('failed')
32pm.matlab.show( failed )
33assert(isempty(val) && failed)
34
35pm.matlab.show()
36pm.matlab.show('[val, failed] = pm.matlab.hashmap.getKeyVal("key2", hashmap(1:4));')
37 [val, failed] = pm.matlab.hashmap.getKeyVal("key2", hashmap(1:4));
38pm.matlab.show('val')
39pm.matlab.show( val )
40pm.matlab.show('failed')
41pm.matlab.show( failed )
42assert(val == "val2" && ~failed)
43
44pm.matlab.show()
45pm.matlab.show('try; pm.matlab.hashmap.getKeyVal("key2", hashmap(1:3)); catch me; disp(string(me.identifier) + string(me.message)); end')
46 try; pm.matlab.hashmap.getKeyVal("key2", hashmap(1:3)); catch me; disp(string(me.identifier) + string(me.message)); end
function root()
Return a scalar MATLAB string containing the root directory of the ParaMonte library package.

Example output
1
2hashmap = {"key1", 1, "key2", "val2", "key3", false};
3
4[val, failed] = pm.matlab.hashmap.getKeyVal("key2", hashmap);
5val
6val
7val2
8failed
9failed
10 0
11
12[val, failed] = pm.matlab.hashmap.getKeyVal("key3", hashmap);
13val
14val
15 0
16failed
17failed
18 0
19
20[val, failed] = pm.matlab.hashmap.getKeyVal("key3", hashmap(1:4));
21val
22val
23failed
24failed
25 1
26
27[val, failed] = pm.matlab.hashmap.getKeyVal("key2", hashmap(1:4));
28val
29val
30val2
31failed
32failed
33 0
34
35try; pm.matlab.hashmap.getKeyVal("key2", hashmap(1:3)); catch me; disp(string(me.identifier) + string(me.message)); end
36 > \brief
37 > Return the value corresponding to the input ``key``
38 > in the input ``hashmap`` cell array.
39 >
40 > \param[in] key : The input scalar MATLAB string
41 > containing the key to search for in the input pair list.
42 >
43 > \param[in] hashmap : The input cell array of even number of elements
44 > containing the ``(key, val)`` pairs of the hashmap
45 > in sequence as element of the cell array.
46 >
47 > \return
48 > ``val`` : The output MATLAB object stored in the element of the
49 > input cell array, whose ``key`` is given as the input.
50 > <br>
51 > ``failed`` : The output scalar MATLAB logical that is ``true``
52 > if and only if the input ``key`` exists in the input ``hashmap``,
53 > otherwise, it is ``false``.<br>
54 > (**optional**. If missing, ``val`` will remain an empty array ``[]`` on output.)
55 >
56 > \interface{getKeyVal}
57 > \code{.m}
58 >
59 > val = pm.matlab.hashmap.getKeyVal(key, hashmap)
60 > [val, failed] = pm.matlab.hashmap.getKeyVal(key, hashmap)
61 >
62 > \endcode
63 >
64 > \warning
65 > The length of the input ``hashmap`` must be even.<br>
66 > Ann odd length of the input cell array will lead to a runtime call to the MATLAB intrinsic ``error()``.<br>
67 >
68 > \example{getKeyVal}
69 > \include{lineno} example/matlab/hashmap/getKeyVal/main.m
70 > \output{getKeyVal}
71 > \include{lineno} example/matlab/hashmap/getKeyVal/main.out.m
72 >
73 > \final{getKeyVal}
74 >
75 > \author
76 > \JoshuaOsborne, May 21 2024, 10:43 PM, University of Texas at Arlington<br>
77 > \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
78 > \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
79
80
81The length of ``hashmap`` must be even.
82
83length(hashmap) = 3
84
85
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.


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