From 0084621bf9f8ede37aa69624fbc4dba3f3568533 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 13 Oct 2020 18:06:29 -0500 Subject: [PATCH 1/3] hashValues - don't copy arrays Co-Authored-By: commy2 <6576312+commy2@users.noreply.github.com> --- addons/hashes/fnc_hashValues.sqf | 2 +- addons/hashes/test_hashes.sqf | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/addons/hashes/fnc_hashValues.sqf b/addons/hashes/fnc_hashValues.sqf index 45e9f8f25..50fb717c0 100644 --- a/addons/hashes/fnc_hashValues.sqf +++ b/addons/hashes/fnc_hashValues.sqf @@ -22,4 +22,4 @@ SCRIPT(hashValues); // ----------------------------------------------------------------------------- params [["_hash", [[], []], [[]]]]; -+(_hash select HASH_VALUES) +[]+(_hash select HASH_VALUES) diff --git a/addons/hashes/test_hashes.sqf b/addons/hashes/test_hashes.sqf index 6664d9543..51392b2b6 100644 --- a/addons/hashes/test_hashes.sqf +++ b/addons/hashes/test_hashes.sqf @@ -18,6 +18,7 @@ TEST_DEFINED("CBA_fnc_hashHasKey",""); TEST_DEFINED("CBA_fnc_isHash",""); TEST_DEFINED("CBA_fnc_hashSize",""); TEST_DEFINED("CBA_fnc_hashKeys",""); +TEST_DEFINED("CBA_fnc_hashValues",""); TEST_FALSE([[]] call CBA_fnc_isHash,"CBA_fnc_isHash"); _hash = [5, [4], [1], 2]; // Not a real hash. @@ -128,4 +129,28 @@ TEST_OP(_keys,isEqualTo,[],"hashKeys"); _keys = [_hash] call CBA_fnc_hashKeys; TEST_OP(_keys,isEqualTo,[ARR_3("123","124",125)],"hashKeys"); +// Test CBA_fnc_hashValues +_hash = [] call CBA_fnc_hashCreate; +private _values = [_hash] call CBA_fnc_hashValues; +TEST_OP(_values,isEqualTo,[],"hashValues - empty"); + +[_hash, "a", 1] call CBA_fnc_hashSet; +[_hash, "b", 2] call CBA_fnc_hashSet; +_values = [_hash] call CBA_fnc_hashValues; +TEST_OP(_values,isEqualTo,[ARR_2(1,2)],"hashValues - values"); + +[_hash, "a"] call CBA_fnc_hashRem; +_values = [_hash] call CBA_fnc_hashValues; +TEST_OP(_values,isEqualTo,[2],"hashValues - removed"); + +_hash = [] call CBA_fnc_hashCreate; +private _data = [3]; +[_hash, "c", _data] call CBA_fnc_hashSet; +_values = [_hash] call CBA_fnc_hashValues; +TEST_OP(_values,isEqualTo,[[3]],"hashValues - array"); + +_data pushBack [7]; +TEST_OP(_values,isEqualTo,[[ARR_2(3,[7])]],"hashValues - deep array copy"); + + nil; From 4b2f72bd645e5d4bfd36292b0dfec2e92fdfb452 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 13 Oct 2020 18:11:37 -0500 Subject: [PATCH 2/3] Update addons/hashes/fnc_hashValues.sqf Co-authored-by: commy2 --- addons/hashes/fnc_hashValues.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hashes/fnc_hashValues.sqf b/addons/hashes/fnc_hashValues.sqf index 50fb717c0..a15b4aaf3 100644 --- a/addons/hashes/fnc_hashValues.sqf +++ b/addons/hashes/fnc_hashValues.sqf @@ -22,4 +22,4 @@ SCRIPT(hashValues); // ----------------------------------------------------------------------------- params [["_hash", [[], []], [[]]]]; -[]+(_hash select HASH_VALUES) + [] + (_hash select HASH_VALUES) // flat-copy From 0a5a938a4abc3a3c8c0a8b8665b0e61d295e790b Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sat, 31 Oct 2020 10:18:16 -0500 Subject: [PATCH 3/3] CBA_fnc_hashKeys returns flat copy as well --- addons/hashes/fnc_hashKeys.sqf | 2 +- addons/hashes/test_hashes.sqf | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/addons/hashes/fnc_hashKeys.sqf b/addons/hashes/fnc_hashKeys.sqf index b72668895..6988e1741 100644 --- a/addons/hashes/fnc_hashKeys.sqf +++ b/addons/hashes/fnc_hashKeys.sqf @@ -22,4 +22,4 @@ SCRIPT(hashKeys); // ----------------------------------------------------------------------------- params [["_hash", [[], []], [[]]]]; -+(_hash select HASH_KEYS) +[] + (_hash select HASH_KEYS) // flat-copy diff --git a/addons/hashes/test_hashes.sqf b/addons/hashes/test_hashes.sqf index 51392b2b6..52ac68354 100644 --- a/addons/hashes/test_hashes.sqf +++ b/addons/hashes/test_hashes.sqf @@ -129,6 +129,16 @@ TEST_OP(_keys,isEqualTo,[],"hashKeys"); _keys = [_hash] call CBA_fnc_hashKeys; TEST_OP(_keys,isEqualTo,[ARR_3("123","124",125)],"hashKeys"); +// Using an array as a key +_hash = [] call CBA_fnc_hashCreate; +private _arrayKey = []; +[_hash, _arrayKey, "whyWouldYouDoThis"] call CBA_fnc_hashSet; +_keys = [_hash] call CBA_fnc_hashKeys; +(_keys select 0) pushBack 7; +TEST_OP(_arrayKey,isEqualTo,[7],"hashKeysDepth"); +_result = [_hash, [7]] call CBA_fnc_hashGet; +TEST_OP(_result,==,"whyWouldYouDoThis","hashKeysDepth"); + // Test CBA_fnc_hashValues _hash = [] call CBA_fnc_hashCreate; private _values = [_hash] call CBA_fnc_hashValues;