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

switch points module to HashMap #62

Merged
merged 2 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions functions/points/fn_addPoints.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ if (_side isEqualTo sideUnknown) exitWith {
false
};

private _sidePoints = [GVAR(points), _side] call CBA_fnc_hashGet;
private _oldSidePointsForCategory = [_sidePoints, _category] call CBA_fnc_hashGet;
[_sidePoints, _category, _oldSidePointsForCategory + _points] call CBA_fnc_hashSet;
[GVAR(points), _side, _sidePoints] call CBA_fnc_hashSet; // returning the default value does *not* imply setting it - so we need to explicitly set this at least once.
private _sidePoints = GVAR(points) getOrDefault [_side, createHashMap];
private _oldSidePointsForCategory = _sidePoints getOrDefault [_category, 0];
_sidePoints set [_category, _oldSidePointsForCategory + _points];
GVAR(points) set [_side, _sidePoints]; // returning the default value does *not* imply setting it - so we need to explicitly set this at least once.

publicVariable QGVAR(points);
true
5 changes: 2 additions & 3 deletions functions/points/fn_getPoints.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ params [
["_side", sideUnknown, [sideUnknown]]
];

private _categorizedPoints = [[GVAR(points), _side] call CBA_fnc_hashGet] call CBA_fnc_hashValues;

private _categorizedPoints = GVAR(points) getOrDefault [_side, createHashMap];
private _sum = 0;
{ _sum = _sum + _x } forEach _categorizedPoints;
{ _sum = _sum + _y } forEach _categorizedPoints;

_sum
7 changes: 3 additions & 4 deletions functions/points/fn_getPointsCategorized.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ params [
];

private _pairs = [];
[
[GVAR(points), _side] call CBA_fnc_hashGet,
{ _pairs pushBack [_key, _value] }
] call CBA_fnc_hashEachPair;
{
_pairs pushBack [_x, _y];
} forEach (GVAR(points) getOrDefault [_side, createHashMap]);

_pairs
5 changes: 1 addition & 4 deletions functions/points/fn_getPointsCategory.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@ params [
["_category", "Other", [""]]
];

[
[GVAR(points), _side] call CBA_fnc_hashGet,
_category
] call CBA_fnc_hashGet
(GVAR(points) getOrDefault [_side, createHashMap]) getOrDefault [_category, 0]
2 changes: 1 addition & 1 deletion functions/points/fn_initPoints.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ ISNILS(GVAR(bounties), [ARR_2([], [ARR_2([], 0)] call CBA_fnc_hashCreate)] call
];

// this is a map<side:SIDE,map<category:STRING,points:SCALAR>>
ISNILS(GVAR(points), [ARR_2([], [ARR_2([], 0)] call CBA_fnc_hashCreate)] call CBA_fnc_hashCreate);
ISNILS(GVAR(points), createHashMap);

[] call grad_points_fnc_addKilledEH;
8 changes: 4 additions & 4 deletions functions/points/fn_setPoints.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ if (_side isEqualTo sideUnknown) exitWith {
false
};

private _sidePoints = [GVAR(points), _side] call CBA_fnc_hashGet;
private _oldSidePointsForCategory = [_sidePoints, _category] call CBA_fnc_hashGet;
[_sidePoints, _category, _points] call CBA_fnc_hashSet;
[GVAR(points), _side, _sidePoints] call CBA_fnc_hashSet; // returning the default value does *not* imply setting it - so we need to explicitly set this at least once.
private _sidePoints = GVAR(points) getOrDefault [_side, createHashMap];
private _oldSidePointsForCategory = _sidePoints getOrDefault [_category, 0];
_sidePoints set [_category, _points];
GVAR(points) set [_side, _sidePoints]; // returning the default value does *not* imply setting it - so we need to explicitly set this at least once.

publicVariable QGVAR(points);
true