Skip to content

Commit

Permalink
manual merge
Browse files Browse the repository at this point in the history
  • Loading branch information
commy2 committed Feb 25, 2016
2 parents a74ab4e + e39c9e9 commit e6abdff
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 51 deletions.
21 changes: 4 additions & 17 deletions addons/hashes/fnc_hashCreate.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,10 @@ Author:
SCRIPT(hashCreate);

// -----------------------------------------------------------------------------
params [["_array", [], [[]]], "_defaultValue"];

DEFAULT_PARAM(0,_array,[]);
DEFAULT_PARAM(1,_defaultValue,nil);
private ["_keys", "_values"];

_keys = [];
_values = [];

_keys resize (count _array);
_values resize (count _array);

for "_i" from 0 to ((count _array) - 1) do
{
_keys set [_i, (_array select _i) select 0];
_values set [_i, (_array select _i) select 1];
};
private _keys = _array apply {_x select 0};
private _values = _array apply {_x select 1};

// Return.
[TYPE_HASH, _keys, _values,
if (isNil "_defaultValue") then { nil } else { _defaultValue }];
[TYPE_HASH, _keys, _values, _defaultValue];
14 changes: 4 additions & 10 deletions addons/hashes/fnc_hashEachPair.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,13 @@ SCRIPT(hashEachPair);

params ["_hash","_code"];

private ["_keys", "_values"];
_hash params ["", "_keys", "_values"];

_keys = _hash select HASH_KEYS;
_values = _hash select HASH_VALUES;

for "_i" from 0 to ((count _keys) - 1) do
{
private ["_key", "_value"];

_key = _keys select _i;
_value = _values select _i;
private _key = _x;
private _value = _values select _forEachIndex;
TRACE_2("VM CHECK",_key,_value);
call _code;
};
} forEach _keys;

nil; // Return.
8 changes: 3 additions & 5 deletions addons/hashes/fnc_hashGet.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,19 @@ Author:
SCRIPT(hashGet);

// -----------------------------------------------------------------------------
private ["_index", "_default", "_new"];
private ["_index", "_default"];
params ["_hash","_key"];
_default = param [2,_hash select HASH_DEFAULT_VALUE];

_index = (_hash select HASH_KEYS) find _key;
if (_index >= 0) then
{
if (_index >= 0) then {
(_hash select HASH_VALUES) select _index; // Return.
} else {
if (isNil "_default") then {
nil // Return
} else {
// Make a copy of the array instead!
if (typeName _default == "ARRAY") then
{
if (_default isEqualType []) then {
_default = + _default;
};
_default // Return.
Expand Down
6 changes: 2 additions & 4 deletions addons/hashes/fnc_hashRem.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ SCRIPT(hashRem);
// ----------------------------------------------------------------------------
params ["_hash","_key"];

private ["_defaultValue"];

_defaultValue = _hash select HASH_DEFAULT_VALUE;
[_hash, _key, if (isNil "_defaultValue") then { nil } else { _defaultValue }] call CBA_fnc_hashSet;
private _defaultValue = _hash select HASH_DEFAULT_VALUE;
[_hash, _key, _defaultValue] call CBA_fnc_hashSet;

_hash; // Return.
17 changes: 5 additions & 12 deletions addons/hashes/fnc_hashSet.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,15 @@ private ["_index", "_isDefault"];
// ----------------------------------------------------------------------------
params ["_hash","_key","_value"];

if (isNil "_value") then { _value = nil};
if (isNil "_key") exitWith {_hash};
if (isNil "_hash") exitWith {_hash;};

if (isNil "BIS_fnc_areEqual") then { LOG( "WARNING: BIS_fnc_areEqual is Nil") };
if (isNil "_hash") exitWith {_hash};

// Work out whether the new value is the default value for this assoc.
_isDefault = [if (isNil "_value") then { nil } else { _value },
_hash select HASH_DEFAULT_VALUE] call (uiNamespace getVariable "BIS_fnc_areEqual");
_isDefault = _value isEqualTo (_hash select HASH_DEFAULT_VALUE);

_index = (_hash select HASH_KEYS) find _key;
if (_index >= 0) then
{
if (_isDefault) then
{
if (_index >= 0) then {
if (_isDefault) then {
// Remove the key, if the new value is the default value.
// Do this by copying the key and value of the last element
// in the hash to the position of the element to be removed.
Expand All @@ -63,8 +57,7 @@ if (_index >= 0) then
};
} else {
// Ignore values that are the same as the default.
if (not _isDefault) then
{
if !(_isDefault) then {
_hash select HASH_KEYS pushBack _key;
_hash select HASH_VALUES pushBack _value;
};
Expand Down
4 changes: 1 addition & 3 deletions addons/hashes/fnc_isHash.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ SCRIPT(isHash);

params ["_value"];

private "_result";

_result = false;
private _result = false;

if ((typeName _value) == "ARRAY" && {(count _value) == 4} && {(typeName (_value select HASH_ID)) == (typeName TYPE_HASH)}) then {
_result = ((_value select HASH_ID) == TYPE_HASH);
Expand Down

0 comments on commit e6abdff

Please sign in to comment.