From 598addb120a1e4b1442f2b70151226b9c734528f Mon Sep 17 00:00:00 2001 From: commy2 Date: Wed, 2 Dec 2015 13:22:58 +0100 Subject: [PATCH 1/2] improve CBA_fnc_findMax performance and fix CBA_fnc_findMin --- addons/arrays/fnc_findMax.sqf | 22 ++++++++-------------- addons/arrays/fnc_findMin.sqf | 22 ++++++++-------------- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/addons/arrays/fnc_findMax.sqf b/addons/arrays/fnc_findMax.sqf index 4e643b3cc..443d7d573 100644 --- a/addons/arrays/fnc_findMax.sqf +++ b/addons/arrays/fnc_findMax.sqf @@ -9,7 +9,7 @@ Parameters: Example: (begin example) - _result = [_array] call CBA_fnc_findMax + _result = [0,4,3,-2] call CBA_fnc_findMax (end) Returns: @@ -18,24 +18,18 @@ Returns: nil on failure Author: - joko // Jonas + joko // Jonas, commy2 ---------------------------------------------------------------------------- */ #include "script_component.hpp" SCRIPT(findMax); -private ["_index"]; +[_this] params [["_array", [], [[]]]]; -if (!IS_ARRAY(_this)) exitWith {nil}; -if (_this isEqualTo []) exitWith {nil}; +if !(_array isEqualTypeAll 0) exitWith {nil}; -params ["_max"]; -_index = 0; +private _arraySorted = + _array; +_arraySorted sort false; // false - descending +_arraySorted params ["_min"]; -{ - if (isNil "_x" || {(typeName _x) != (typeName 0)}) exitWith {_max = nil; _index = nil;}; - if (_max < _x) then {_max = _x; _index = _forEachIndex}; -} forEach _this; - -if (isNil "_max") exitWith {nil}; -[_max, _index] // Return +[_min, _array find _min] diff --git a/addons/arrays/fnc_findMin.sqf b/addons/arrays/fnc_findMin.sqf index 8e41f5320..e4edddca7 100644 --- a/addons/arrays/fnc_findMin.sqf +++ b/addons/arrays/fnc_findMin.sqf @@ -9,7 +9,7 @@ Parameters: Example: (begin example) - _result = [_array] call CBA_fnc_findMin + _result = [0,4,3,-2] call CBA_fnc_findMin (end) Returns: @@ -18,24 +18,18 @@ Returns: nil on failure Author: - joko // Jonas + joko // Jonas, commy2 ---------------------------------------------------------------------------- */ #include "script_component.hpp" SCRIPT(findMin); -private ["_index"]; +[_this] params [["_array", [], [[]]]]; -if (!IS_ARRAY(_this)) exitWith {nil}; -if (_this isEqualTo []) exitWith {nil}; +if !(_array isEqualTypeAll 0) exitWith {nil}; -params ["_min"]; -_index = 0; +private _arraySorted = + _array; +_arraySorted sort true; // true - ascending +_arraySorted params ["_min"]; -{ - if (isNil "_x" || {(typeName _x) != (typeName 0)}) exitWith {_max = nil; _index = nil;}; - if (_min > _x) then {_min = _x; _index = _forEachIndex}; -} forEach _this; - -if (isNil "_max") exitWith {nil}; -[_min, _index] // Return +[_min, _array find _min] From 5cce962ab079bf9ddc5f1a99e6c479395a4e40e9 Mon Sep 17 00:00:00 2001 From: commy2 Date: Wed, 2 Dec 2015 13:25:12 +0100 Subject: [PATCH 2/2] rename variable _min to _max in CBA_fnc_findMax --- addons/arrays/fnc_findMax.sqf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/arrays/fnc_findMax.sqf b/addons/arrays/fnc_findMax.sqf index 443d7d573..abcfbafba 100644 --- a/addons/arrays/fnc_findMax.sqf +++ b/addons/arrays/fnc_findMax.sqf @@ -30,6 +30,6 @@ if !(_array isEqualTypeAll 0) exitWith {nil}; private _arraySorted = + _array; _arraySorted sort false; // false - descending -_arraySorted params ["_min"]; +_arraySorted params ["_max"]; -[_min, _array find _min] +[_max, _array find _max]