CBA_A3 icon indicating copy to clipboard operation
CBA_A3 copied to clipboard

CBA_fnc_hashSet deleting default values is ... just bad

Open Fusselwurm opened this issue 4 years ago • 2 comments

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.

Fusselwurm avatar Jul 23 '20 15:07 Fusselwurm

for a quick & easy solution, maybe a third parameter on hash creation to make the behavior explicit?

Fusselwurm avatar Jul 23 '20 15:07 Fusselwurm

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.

commy2 avatar Jul 23 '20 16:07 commy2