This is a request for a setDefault bool parameter to be added to the getOrDefault command. This parameter (when set to true, default: false) would make the command work similarly to Python's dictionary.setdefault(keyname, value) method. That is, if the given key does not exist in the hash map, then the default value is still returned but the key is also set to the default value in the hash map.
This would allow the following code (_faction is some faction class name and _vehicle is some vehicle class name):
private _hashMap = createHashMap; private _list = _hashMap get _faction; if (isNil "_list") then { _list = []; _hashMap set [_faction, _list]; }; _list pushBack _vehicle;
to be simplified as:
private _hashMap = createHashMap; private _list = _hashMap getOrDefault [_faction, [], true]; // <- set default parameter _list pushBack _vehicle;
The new syntax for the getOrDefault command would look like: hashMap getOrDefault [key, defaultValue, setDefault]
- hashMap <HashMap>
- key <HashMapKey>
- defaultValue <ANY> (optional, default: nil)
- setDefault <BOOL> (optional, default false)