Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CBA_fnc_hashSet deleting default values is ... just bad #1358

Open
Fusselwurm opened this issue Jul 23, 2020 · 2 comments
Open

CBA_fnc_hashSet deleting default values is ... just bad #1358

Fusselwurm opened this issue Jul 23, 2020 · 2 comments
Labels

Comments

@Fusselwurm
Copy link
Contributor

Fusselwurm commented Jul 23, 2020

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 Fusselwurm added the Bug label Jul 23, 2020
@Fusselwurm
Copy link
Contributor Author

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

@commy2
Copy link
Contributor

commy2 commented Jul 23, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants