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

Update some array functions #635

Merged
merged 11 commits into from
Apr 15, 2017
Merged

Conversation

Dorbedo
Copy link
Contributor

@Dorbedo Dorbedo commented Apr 10, 2017

  • Usage of the new selectMin / selectMax commands
  • select update
  • TODO for shuffle done

approx 10x faster
added a new feature, removed the old warning

[_min, _array find _min]
private _max = selectMin _array;
[_max, _array find _max]
Copy link
Contributor

Choose a reason for hiding this comment

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

Variable name should still be _min :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

c&p, fixed

[] + _this;
};
};
_this params [["_array",[],[[]]],["_inPlace",false,[false]]];
Copy link
Contributor

Choose a reason for hiding this comment

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

The _this is superfluous as it's the variable used by the default unary syntax of params.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just personal style, the compiler is adding it anyways

I can remove it, if you like.

Copy link
Contributor

Choose a reason for hiding this comment

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

The Arma compiler does not add _this to the unary syntax of params.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, I don't know why I was thinking this.

} forEach _array;

_result
_array select {_x call _filterCode}
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes the function no longer support _forEachIndex!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhh, I remember. I'll remove.

@commy2
Copy link
Contributor

commy2 commented Apr 10, 2017

Re CBA_fnc_select. The same optimization was made to CBA_fnc_reject and no one complained.
fc75b17
My thought was, that these functions are kinda deprecated now anyways so why risk breaking something that uses them?

@Dorbedo
Copy link
Contributor Author

Dorbedo commented Apr 10, 2017

So mark them as deprecated and revert fc75b17 too?

@commy2
Copy link
Contributor

commy2 commented Apr 10, 2017

I'd say yes.

If (_inPlace) then {
for "_size" from (count _tempArray) to 1 step -1 do {
_array set [_size-1,(_tempArray deleteAt (floor random _size))];
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we still return the array here?

@commy2
Copy link
Contributor

commy2 commented Apr 10, 2017

^ please change the tests in a separate pull request. This is to make sure that potential errors aren't missed.

Dorbedo added a commit to Dorbedo/CBA_A3 that referenced this pull request Apr 10, 2017
@Dorbedo Dorbedo mentioned this pull request Apr 10, 2017
@Dorbedo
Copy link
Contributor Author

Dorbedo commented Apr 10, 2017

Alright.

@commy2
Copy link
Contributor

commy2 commented Apr 11, 2017

 3:45:58 [CBA] (arrays) LOG: === Testing Arrays === x\cba\addons\arrays\test.sqf:13
 3:45:58 [CBA] (arrays) LOG: Testing CBA_fnc_filter x\cba\addons\arrays\test_filter.sqf:12
 3:45:58 [CBA] (arrays) Test OK: (CBA_fnc_filter is defined) x\cba\addons\arrays\test_filter.sqf:14
 3:45:58 [CBA] (arrays) Test OK: (str _result == str _expected) x\cba\addons\arrays\test_filter.sqf:20
 3:45:58 [CBA] (arrays) Test OK: (str _original == str _expected) x\cba\addons\arrays\test_filter.sqf:21
 3:45:58 [CBA] (arrays) Test OK: (str _result == str _expected) x\cba\addons\arrays\test_filter.sqf:26
 3:45:58 [CBA] (arrays) Test OK: (str _original != str _expected) x\cba\addons\arrays\test_filter.sqf:27
 3:45:58 [CBA] (arrays) Test OK: (str _result == str _expected) x\cba\addons\arrays\test_filter.sqf:32
 3:45:58 [CBA] (arrays) Test OK: (str _original == str _expected) x\cba\addons\arrays\test_filter.sqf:38
 3:45:58 [CBA] (arrays) Test OK: (str _result == str _expected) x\cba\addons\arrays\test_filter.sqf:39
 3:45:58 [CBA] (arrays) Test OK: (str _original == str _expected) x\cba\addons\arrays\test_filter.sqf:44
 3:45:58 [CBA] (arrays) Test OK: (str _result == str _expected) x\cba\addons\arrays\test_filter.sqf:45
 3:45:58 [CBA] (arrays) Test OK: (str _original == str _expected) x\cba\addons\arrays\test_filter.sqf:50
 3:45:58 [CBA] (arrays) Test OK: (str _result == str _expected) x\cba\addons\arrays\test_filter.sqf:51
 3:45:58 [CBA] (arrays) LOG: Testing CBA_fnc_inject x\cba\addons\arrays\test_inject.sqf:12
 3:45:58 [CBA] (arrays) Test OK: (CBA_fnc_inject is defined) x\cba\addons\arrays\test_inject.sqf:14
 3:45:58 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_inject.sqf:18
 3:45:58 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_inject.sqf:22
 3:45:58 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_inject.sqf:26
 3:45:58 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_inject.sqf:30
 3:45:58 [CBA] (arrays) LOG: Testing CBA_fnc_join x\cba\addons\arrays\test_join.sqf:12
 3:45:58 [CBA] (arrays) Test OK: (CBA_fnc_join is defined) x\cba\addons\arrays\test_join.sqf:14
 3:45:58 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_join.sqf:18
 3:45:58 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_join.sqf:22
 3:45:58 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_join.sqf:26
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_join.sqf:30
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_join.sqf:34
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_join.sqf:38
 3:45:59 [CBA] (arrays) ERROR: Test FAIL x\cba\addons\arrays\test_shuffle.sqf:27
 3:45:59             (count _result == count _original)
 3:45:59 [CBA] (arrays) LOG: Testing CBA_fnc_shuffle x\cba\addons\arrays\test_shuffle.sqf:12
 3:45:59 [CBA] (arrays) Test OK: (CBA_fnc_shuffle is defined) x\cba\addons\arrays\test_shuffle.sqf:14
 3:45:59 [CBA] (arrays) Test OK: (count _result == count _original) x\cba\addons\arrays\test_shuffle.sqf:18
 3:45:59 [CBA] (arrays) Test OK: (_x in _original) x\cba\addons\arrays\test_shuffle.sqf:21
 3:45:59 [CBA] (arrays) Test OK: (_x in _original) x\cba\addons\arrays\test_shuffle.sqf:21
 3:45:59 [CBA] (arrays) Test OK: (_x in _original) x\cba\addons\arrays\test_shuffle.sqf:21
 3:45:59 [CBA] (arrays) Test OK: (count _result == count _original) x\cba\addons\arrays\test_shuffle.sqf:36
 3:45:59 [CBA] (arrays) LOG: Testing CBA_fnc_findNil x\cba\addons\arrays\test_findNil.sqf:13
 3:45:59 [CBA] (arrays) Test OK: (CBA_fnc_findNil is defined) x\cba\addons\arrays\test_findNil.sqf:15
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findNil.sqf:20
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findNil.sqf:25
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findNil.sqf:30
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findNil.sqf:35
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findNil.sqf:40
 3:45:59 [CBA] (arrays) LOG: Testing CBA_fnc_findNull x\cba\addons\arrays\test_findNull.sqf:13
 3:45:59 [CBA] (arrays) Test OK: (CBA_fnc_findNull is defined) x\cba\addons\arrays\test_findNull.sqf:15
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findNull.sqf:20
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findNull.sqf:25
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findNull.sqf:30
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findNull.sqf:35
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findNull.sqf:40
 3:45:59 [CBA] (arrays) LOG: Testing CBA_fnc_findTypeName x\cba\addons\arrays\test_findTypeName.sqf:13
 3:45:59 [CBA] (arrays) Test OK: (CBA_fnc_findTypeName is defined) x\cba\addons\arrays\test_findTypeName.sqf:15
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:22
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:26
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:30
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:34
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:38
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:42
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:46
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:50
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:54
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:58
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:62
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:66
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:70
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:74
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:78
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:82
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:87
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:92
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:97
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:102
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:107
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:112
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeName.sqf:117
 3:45:59 [CBA] (arrays) LOG: Testing CBA_fnc_findTypeOf x\cba\addons\arrays\test_findTypeOf.sqf:12
 3:45:59 [CBA] (arrays) Test OK: (CBA_fnc_findTypeOf is defined) x\cba\addons\arrays\test_findTypeOf.sqf:14
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeOf.sqf:19
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeOf.sqf:24
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeOf.sqf:29
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeOf.sqf:34
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeOf.sqf:39
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeOf.sqf:44
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeOf.sqf:49
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeOf.sqf:54
 3:45:59 [CBA] (arrays) Test OK: (_result == _expected) x\cba\addons\arrays\test_findTypeOf.sqf:59
 3:45:59 [CBA] (arrays) LOG: Testing CBA_fnc_findMax x\cba\addons\arrays\test_findMax.sqf:13
 3:45:59 [CBA] (arrays) Test OK: (CBA_fnc_findMax is defined) x\cba\addons\arrays\test_findMax.sqf:15
 3:45:59 [CBA] (arrays) Test OK: (_result isEqualTo _expected) x\cba\addons\arrays\test_findMax.sqf:20
 3:45:59 [CBA] (arrays) Test OK: (_result isEqualTo _expected) x\cba\addons\arrays\test_findMax.sqf:25
 3:45:59 [CBA] (arrays) Test OK: (_result isEqualTo _expected) x\cba\addons\arrays\test_findMax.sqf:30
 3:45:59 [CBA] (arrays) Test OK: (_result isEqualTo _expected) x\cba\addons\arrays\test_findMax.sqf:35
 3:45:59 [CBA] (arrays) Test OK: (_result isEqualTo _expected) x\cba\addons\arrays\test_findMax.sqf:40
 3:45:59 [CBA] (arrays) Test OK: (_result isEqualTo _expected) x\cba\addons\arrays\test_findMax.sqf:45
 3:45:59 [CBA] (arrays) Test OK: (isNil "_result") x\cba\addons\arrays\test_findMax.sqf:49
 3:45:59 [CBA] (arrays) Test OK: (isNil "_result") x\cba\addons\arrays\test_findMax.sqf:53
 3:45:59 [CBA] (arrays) Test OK: (isNil "_result") x\cba\addons\arrays\test_findMax.sqf:57
 3:45:59 [CBA] (arrays) LOG: Testing CBA_fnc_findMin x\cba\addons\arrays\test_findMin.sqf:12
 3:45:59 [CBA] (arrays) Test OK: (CBA_fnc_findMin is defined) x\cba\addons\arrays\test_findMin.sqf:14
 3:45:59 [CBA] (arrays) Test OK: (_result isEqualTo _expected) x\cba\addons\arrays\test_findMin.sqf:19
 3:45:59 [CBA] (arrays) Test OK: (_result isEqualTo _expected) x\cba\addons\arrays\test_findMin.sqf:24
 3:45:59 [CBA] (arrays) Test OK: (_result isEqualTo _expected) x\cba\addons\arrays\test_findMin.sqf:29
 3:45:59 [CBA] (arrays) Test OK: (_result isEqualTo _expected) x\cba\addons\arrays\test_findMin.sqf:34
 3:45:59 [CBA] (arrays) Test OK: (_result isEqualTo _expected) x\cba\addons\arrays\test_findMin.sqf:39
 3:45:59 [CBA] (arrays) Test OK: (_result isEqualTo _expected) x\cba\addons\arrays\test_findMin.sqf:44
 3:45:59 [CBA] (arrays) Test OK: (isNil "_result") x\cba\addons\arrays\test_findMin.sqf:48
 3:45:59 [CBA] (arrays) Test OK: (isNil "_result") x\cba\addons\arrays\test_findMin.sqf:52
 3:45:59 [CBA] (arrays) Test OK: (isNil "_result") x\cba\addons\arrays\test_findMin.sqf:56
 3:45:59 [CBA] (arrays) Test OK: (isNil "_result") x\cba\addons\arrays\test_findMin.sqf:60
 3:45:59 [CBA] (arrays) Test OK: (isNil "_result") x\cba\addons\arrays\test_findMin.sqf:64
 3:45:59 [CBA] (arrays) LOG: Testing CBA_fnc_insert x\cba\addons\arrays\test_insert.sqf:12
 3:45:59 [CBA] (arrays) Test OK: (CBA_fnc_insert is defined) x\cba\addons\arrays\test_insert.sqf:14
 3:45:59 [CBA] (arrays) Test OK: (_result isEqualTo _expected) x\cba\addons\arrays\test_insert.sqf:20
 3:45:59 [CBA] (arrays) Test OK: (_result isEqualTo _expected) x\cba\addons\arrays\test_insert.sqf:26

@commy2
Copy link
Contributor

commy2 commented Apr 11, 2017

This pull request drops support for the deprecated syntax of the function:

// Support the deprecated parameter style: [1, 2, 3, 4, 5] call CBA_fnc_shuffle.
_tempArray = if (count _this != 1) then {
    WARNING("CBA_fnc_shuffle requires an array as first parameter, not just a direct array: " + str _this);
    [] + _this;
} else {
    if (IS_ARRAY(_this select 0)) then {
        [] + (_this select 0); // Correct params passed.
    } else {
        WARNING("CBA_fnc_shuffle requires an array as first parameter, not just a direct array: " + str _this);
         [] + _this;
     };
 };

@commy2 commy2 added this to the 3.4 milestone Apr 11, 2017
@commy2
Copy link
Contributor

commy2 commented Apr 11, 2017

It's probably fine, because it's logged as deprecated anyways.

@Dorbedo can you please merge Dorbedo#1 ?

@commy2 commy2 merged commit 0a2ab80 into CBATeam:master Apr 15, 2017
commy2 pushed a commit that referenced this pull request Apr 15, 2017
* new shuffle test

#635

* Keeping the old test
@Dorbedo Dorbedo deleted the component_arrays_update branch April 15, 2017 14:48
@commy2 commy2 modified the milestones: 3.3, 3.4 Apr 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants