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

Add Function to retrieve all Keys in a Hash #590

Merged
merged 2 commits into from
Feb 15, 2017

Conversation

dedmen
Copy link
Contributor

@dedmen dedmen commented Feb 14, 2017

I am currently doing
params ["", "_keys"] to get the keys of a hash.
But that might break if the internal structure changes.
So rather have a offical API function for that.

// CBA_fnc_hashGetKeys
class hashGetKeys
{
description = "Returns all the Keys in a Hash";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returns all the Keys in a Hash .

Function: CBA_fnc_hashGetKeys

Description:
Returns all the Keys in a Hash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@commy2 commy2 added this to the 3.2 milestone Feb 14, 2017
@commy2 commy2 added the Feature label Feb 14, 2017
Copy link
Contributor

@commy2 commy2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add 2 or 3 examples to test_hashes.sqf. Thanks.

@dedmen
Copy link
Contributor Author

dedmen commented Feb 14, 2017

My imagination to make up tests is not that good.

@commy2
Copy link
Contributor

commy2 commented Feb 14, 2017

test fails, because of this line:
TEST_OP(_keys,isEqualTo,["123","124",125],"hashSize");
Array uses additional commas. Suggest to either use ARR_3() macro or to use the _expected variable.

@commy2
Copy link
Contributor

commy2 commented Feb 14, 2017

Also put a period after "Returns all the Keys in a Hash" while you're at it. Thanks.

@dedmen
Copy link
Contributor Author

dedmen commented Feb 14, 2017

All the pointy things!

@commy2
Copy link
Contributor

commy2 commented Feb 15, 2017

execVM "\x\cba\addons\hashes\test_hashes.sqf"
[CBA] (hashes) Test OK: (CBA_fnc_hashCreate is defined) x\cba\addons\hashes\test_hashes.sqf:14
[CBA] (hashes) Test OK: (CBA_fnc_hashGet is defined) x\cba\addons\hashes\test_hashes.sqf:15
[CBA] (hashes) Test OK: (CBA_fnc_hashSet is defined) x\cba\addons\hashes\test_hashes.sqf:16
[CBA] (hashes) Test OK: (CBA_fnc_hashHasKey is defined) x\cba\addons\hashes\test_hashes.sqf:17
[CBA] (hashes) Test OK: (CBA_fnc_isHash is defined) x\cba\addons\hashes\test_hashes.sqf:18
[CBA] (hashes) Test OK: (CBA_fnc_hashSize is defined) x\cba\addons\hashes\test_hashes.sqf:19
[CBA] (hashes) Test OK: (CBA_fnc_hashGetKeys is defined) x\cba\addons\hashes\test_hashes.sqf:20
[CBA] (hashes) Test OK: (not ([[]] call CBA_fnc_isHash)) x\cba\addons\hashes\test_hashes.sqf:22
[CBA] (hashes) Test OK: (not ([_hash] call CBA_fnc_isHash)) x\cba\addons\hashes\test_hashes.sqf:24
[CBA] (hashes) Test OK: (not ([5] call CBA_fnc_isHash)) x\cba\addons\hashes\test_hashes.sqf:25
[CBA] (hashes) Test OK: (_hash is defined) x\cba\addons\hashes\test_hashes.sqf:29
[CBA] (hashes) Test OK: ([_hash] call CBA_fnc_isHash) x\cba\addons\hashes\test_hashes.sqf:30
[CBA] (hashes) Test OK: (not (_result)) x\cba\addons\hashes\test_hashes.sqf:33
[CBA] (hashes) Test OK: ([_hash] call CBA_fnc_isHash) x\cba\addons\hashes\test_hashes.sqf:36
[CBA] (hashes) Test OK: (_result == 12) x\cba\addons\hashes\test_hashes.sqf:39
[CBA] (hashes) Test OK: (_result) x\cba\addons\hashes\test_hashes.sqf:42
[CBA] (hashes) Test OK: (not (_result)) x\cba\addons\hashes\test_hashes.sqf:45
[CBA] (hashes) Test OK: (isNil "_result") x\cba\addons\hashes\test_hashes.sqf:51
[CBA] (hashes) Test OK: (isNil "_result") x\cba\addons\hashes\test_hashes.sqf:58
[CBA] (hashes) Test OK: (isNil "_result") x\cba\addons\hashes\test_hashes.sqf:62
[CBA] (hashes) Test OK: ([_hash] call CBA_fnc_isHash) x\cba\addons\hashes\test_hashes.sqf:66
[CBA] (hashes) Test OK: (_result is defined) x\cba\addons\hashes\test_hashes.sqf:69
[CBA] (hashes) Test OK: (_result == 99) x\cba\addons\hashes\test_hashes.sqf:70
[CBA] (hashes) Test OK: ([_hash] call CBA_fnc_isHash) x\cba\addons\hashes\test_hashes.sqf:74
[CBA] (hashes) Test OK: (_result is defined) x\cba\addons\hashes\test_hashes.sqf:77
[CBA] (hashes) Test OK: (_result == -8) x\cba\addons\hashes\test_hashes.sqf:78
[CBA] (hashes) Test OK: (_result is defined) x\cba\addons\hashes\test_hashes.sqf:81
[CBA] (hashes) Test OK: (_result == 0) x\cba\addons\hashes\test_hashes.sqf:82
[CBA] (hashes) Test OK: (_result is defined) x\cba\addons\hashes\test_hashes.sqf:86
[CBA] (hashes) Test OK: (_result == 1) x\cba\addons\hashes\test_hashes.sqf:87
[CBA] (hashes) Test OK: (isNil "_result") x\cba\addons\hashes\test_hashes.sqf:91
[CBA] (hashes) ERROR: Test FAIL x\cba\addons\hashes\test_hashes.sqf:129
[CBA] (hashes) Test OK: (_size == 0) x\cba\addons\hashes\test_hashes.sqf:96
[CBA] (hashes) Test OK: (_size == 1) x\cba\addons\hashes\test_hashes.sqf:101
[CBA] (hashes) Test OK: (_size == 3) x\cba\addons\hashes\test_hashes.sqf:107
[CBA] (hashes) Test OK: (_size == 2) x\cba\addons\hashes\test_hashes.sqf:112
[CBA] (hashes) Test OK: (_size == -1) x\cba\addons\hashes\test_hashes.sqf:117
[CBA] (hashes) Test OK: (_keys isEqualTo []) x\cba\addons\hashes\test_hashes.sqf:122
            (_keys isEqualTo ["123", "124", 125])

[_hash, "123", 1] call CBA_fnc_hashSet;
[_hash, "124", 2] call CBA_fnc_hashSet;
[_hash, 125, 3] call CBA_fnc_hashSet;
_keys = [_hash] call CBA_fnc_hashSize;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CBA_fnc_hashGetKeys

[_hash, "124", 2] call CBA_fnc_hashSet;
[_hash, 125, 3] call CBA_fnc_hashSet;
_keys = [_hash] call CBA_fnc_hashSize;
TEST_OP(_keys,isEqualTo,[ARR_3("123","124",125)],"hashSize");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"hashGetKeys"

@commy2
Copy link
Contributor

commy2 commented Feb 15, 2017

Should this function be called CBA_fnc_hashKeys instead of CBA_fnc_hashGetKeys?

@dedmen
Copy link
Contributor Author

dedmen commented Feb 15, 2017

I thought about that. But with getKeys it's more clear that you get something IMO.

@dedmen
Copy link
Contributor Author

dedmen commented Feb 15, 2017

Thats what you get for copy pasting stuff.

@commy2
Copy link
Contributor

commy2 commented Feb 15, 2017

[CBA] (hashes) Test OK: (CBA_fnc_hashCreate is defined) x\cba\addons\hashes\test_hashes.sqf:14
[CBA] (hashes) Test OK: (CBA_fnc_hashGet is defined) x\cba\addons\hashes\test_hashes.sqf:15
[CBA] (hashes) Test OK: (CBA_fnc_hashSet is defined) x\cba\addons\hashes\test_hashes.sqf:16
[CBA] (hashes) Test OK: (CBA_fnc_hashHasKey is defined) x\cba\addons\hashes\test_hashes.sqf:17
[CBA] (hashes) Test OK: (CBA_fnc_isHash is defined) x\cba\addons\hashes\test_hashes.sqf:18
[CBA] (hashes) Test OK: (CBA_fnc_hashSize is defined) x\cba\addons\hashes\test_hashes.sqf:19
[CBA] (hashes) Test OK: (CBA_fnc_hashGetKeys is defined) x\cba\addons\hashes\test_hashes.sqf:20
[CBA] (hashes) Test OK: (not ([[]] call CBA_fnc_isHash)) x\cba\addons\hashes\test_hashes.sqf:22
[CBA] (hashes) Test OK: (not ([_hash] call CBA_fnc_isHash)) x\cba\addons\hashes\test_hashes.sqf:24
[CBA] (hashes) Test OK: (not ([5] call CBA_fnc_isHash)) x\cba\addons\hashes\test_hashes.sqf:25
[CBA] (hashes) Test OK: (_hash is defined) x\cba\addons\hashes\test_hashes.sqf:29
[CBA] (hashes) Test OK: ([_hash] call CBA_fnc_isHash) x\cba\addons\hashes\test_hashes.sqf:30
[CBA] (hashes) Test OK: (not (_result)) x\cba\addons\hashes\test_hashes.sqf:33
[CBA] (hashes) Test OK: ([_hash] call CBA_fnc_isHash) x\cba\addons\hashes\test_hashes.sqf:36
[CBA] (hashes) Test OK: (_result == 12) x\cba\addons\hashes\test_hashes.sqf:39
[CBA] (hashes) Test OK: (_result) x\cba\addons\hashes\test_hashes.sqf:42
[CBA] (hashes) Test OK: (not (_result)) x\cba\addons\hashes\test_hashes.sqf:45
[CBA] (hashes) Test OK: (isNil "_result") x\cba\addons\hashes\test_hashes.sqf:51
[CBA] (hashes) Test OK: (isNil "_result") x\cba\addons\hashes\test_hashes.sqf:58
[CBA] (hashes) Test OK: (isNil "_result") x\cba\addons\hashes\test_hashes.sqf:62
[CBA] (hashes) Test OK: ([_hash] call CBA_fnc_isHash) x\cba\addons\hashes\test_hashes.sqf:66
[CBA] (hashes) Test OK: (_result is defined) x\cba\addons\hashes\test_hashes.sqf:69
[CBA] (hashes) Test OK: (_result == 99) x\cba\addons\hashes\test_hashes.sqf:70
[CBA] (hashes) Test OK: ([_hash] call CBA_fnc_isHash) x\cba\addons\hashes\test_hashes.sqf:74
[CBA] (hashes) Test OK: (_result is defined) x\cba\addons\hashes\test_hashes.sqf:77
[CBA] (hashes) Test OK: (_result == -8) x\cba\addons\hashes\test_hashes.sqf:78
[CBA] (hashes) Test OK: (_result is defined) x\cba\addons\hashes\test_hashes.sqf:81
[CBA] (hashes) Test OK: (_result == 0) x\cba\addons\hashes\test_hashes.sqf:82
[CBA] (hashes) Test OK: (_result is defined) x\cba\addons\hashes\test_hashes.sqf:86
[CBA] (hashes) Test OK: (_result == 1) x\cba\addons\hashes\test_hashes.sqf:87
[CBA] (hashes) Test OK: (isNil "_result") x\cba\addons\hashes\test_hashes.sqf:91
[CBA] (hashes) Test OK: (_size == 0) x\cba\addons\hashes\test_hashes.sqf:96
[CBA] (hashes) Test OK: (_size == 1) x\cba\addons\hashes\test_hashes.sqf:101
[CBA] (hashes) Test OK: (_size == 3) x\cba\addons\hashes\test_hashes.sqf:107
[CBA] (hashes) Test OK: (_size == 2) x\cba\addons\hashes\test_hashes.sqf:112
[CBA] (hashes) Test OK: (_size == -1) x\cba\addons\hashes\test_hashes.sqf:117
[CBA] (hashes) Test OK: (_keys isEqualTo []) x\cba\addons\hashes\test_hashes.sqf:122
[CBA] (hashes) Test OK: (_keys isEqualTo ["123", "124", 125]) x\cba\addons\hashes\test_hashes.sqf:129

// -----------------------------------------------------------------------------
params [["_hash", [[], []], [[]]]];

(_hash select HASH_KEYS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline @ EOF

Should this array be copied?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What?! I swear I have asked if you think it should be copied. Apparently I thought of it but never did it. My brain is smoosh. Yeah.. Copy is probably better But there may also be a use for byref

@dedmen dedmen force-pushed the hashGetKeys branch 2 times, most recently from 89ae448 to 8c708ea Compare February 15, 2017 15:52
@dedmen
Copy link
Contributor Author

dedmen commented Feb 15, 2017

Should finally be all fine now. Except maybe renaming it to hashKeys. Your decision.

@commy2
Copy link
Contributor

commy2 commented Feb 15, 2017

Now you put two newlines at the end.
Why is this so painful? /O\

@commy2
Copy link
Contributor

commy2 commented Feb 15, 2017

I'd prefer hashKeys. No need to name a getter only function getX and it would just lead to confusions with hashGet which is a different thing altogether.

Add pointy things
Add Tests
@dedmen
Copy link
Contributor Author

dedmen commented Feb 15, 2017

I'll never make a small CBA function again. It's too much hassle ^^

[_hash, "124", 2] call CBA_fnc_hashSet;
[_hash, 125, 3] call CBA_fnc_hashSet;
_keys = [_hash] call CBA_fnc_hashKeys;
TEST_OP(_keys,isEqualTo,[ARR_3("123","124",125)],"hashGetKeys");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hashKeys

// Empty hash keys
_hash = [] call CBA_fnc_hashCreate;
_keys = [_hash] call CBA_fnc_hashKeys;
TEST_OP(_keys,isEqualTo,[],"hashGetKeys");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hashKeys

@commy2
Copy link
Contributor

commy2 commented Feb 15, 2017

I'll never make a small CBA function again. It's too much hassle ^^

I could've fixed it all in one go if I had push access to your branch. Maybe a secondary PR next time...

@dedmen
Copy link
Contributor Author

dedmen commented Feb 15, 2017

Edits from maintainers are allowed :x So you should have access

@commy2
Copy link
Contributor

commy2 commented Feb 15, 2017

lol
Why didn't you tell me earlier.

@commy2 commy2 merged commit 6c62a05 into CBATeam:master Feb 15, 2017
shukari added a commit to shukari/task-force-arma-3-radio that referenced this pull request Apr 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants