CBA_A3
CBA_A3 copied to clipboard
CBA_fnc_hashSet deleting default values is ... just bad
Mods (complete and add to the following information):
- Arma 3: not applicable
- CBA: every version ever
Description:
CBA_fnc_hashSet
removes an entry if the new value equals the default value.
This is cool for a simple key-value store, but leads to unexpected behavior for functions that access the whole dataset, like CBA_fnc_hashEachPair
or CBA_fnc_hashKeys
.
Example:
private _hash = [[], 1] call CBA_fnc_hashCreate;
[_hash, "a", 0] call CBA_fnc_hashSet;
[_hash, "b", 1] call CBA_fnc_hashSet;
[_hash] call CBA_fnc_hashKeys;
// "a" ⚡
Expected behavior:
Do not delete values unless user explicitly calls for that.
for a quick & easy solution, maybe a third parameter on hash creation to make the behavior explicit?
Agreed with this behaviour being bad. I don't even have an explanation why this would be the case. Premature optimization?
However, this behaviour is legacy. I fear that changing the default of hashSet now would break some (obscure?) things. So if a "clear if value is default" flag is added to hashSet, it should default to true
.