append: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Text replacement - " {2,}\}\}" to " }}") |
Lou Montana (talk | contribs) |
||
(22 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{ | {{RV|type=command | ||
| arma3 | |game1= arma3 | ||
|version1= 1.40 | |||
|1.40 | |||
|gr1= Arrays | |gr1= Arrays | ||
| Appends array2 to the back of array1 modifying array1. | |descr= Appends array2 to the back of array1 modifying array1. See [[insert]] for an "appendUnique" equivalent. | ||
{{ | {{Feature|informative|[[append]] does not return array, it modifies the existing array. If you need to return a copy, use "[[+]]": <sqf>array3 = array1 + array2;</sqf>}} | ||
< | |||
| array1 | |s1= array1 [[append]] array2 | ||
|p1= array1: [[Array]] | |p1= array1: [[Array]] | ||
Line 17: | Line 15: | ||
|p2= array2: [[Array]] | |p2= array2: [[Array]] | ||
| [[Nothing]] | |r1= [[Nothing]] | ||
|x1= < | |x1= <sqf> | ||
_arr | _arr = [1,2,3]; | ||
_arr append [4,5,6]; | |||
hint str _arr; // [1,2,3,4,5,6] | |||
</sqf> | |||
| [[set]] | |seealso= [[set]] [[pushBack]] [[pushBackUnique]] [[insert]] [[+]] [[apply]] [[select]] [[resize]] [[reverse]] [[count]] [[deleteAt]] [[deleteRange]] | ||
}} | }} | ||
{{ | {{Note | ||
|user= Heeeere's Johnny! | |||
|timestamp= 20150309004100 | |||
|text= <sqf>_array1 append _array2;</sqf> | |||
is roughly 1.2× faster (depending on array size) than | |||
<sqf>_array1 = _array1 + _array2</sqf> | |||
(Averaged over 10.000 iterations with two identical arrays containing the numbers 0 through 9)<br> | |||
< | |||
The larger the arrays to append, the faster [[append]] is as it does not create a new array, which happens with array addition. | The larger the arrays to append, the faster [[append]] is as it does not create a new array, which happens with array addition. | ||
}} | |||
{{Note | |||
|user= Killzone_Kid | |||
|timestamp= 20150521102700 | |||
Array "unshift" implementation using [[append]], a faster alternative to [[BIS_fnc_arrayUnShift]]: | |text= Array "unshift" implementation using [[append]], a faster alternative to [[BIS_fnc_arrayUnShift]]: | ||
< | <sqf> | ||
KK_fnc_unshift = { | |||
_arr | private ["_arr", "_tmp"]; | ||
_tmp | _arr = _this select 0; | ||
_tmp | _tmp = [_this select 1]; | ||
_arr | _tmp append _arr; | ||
_arr | _arr resize 0; | ||
_arr append _tmp; | |||
_arr | _arr | ||
}; | }; | ||
// Example | // Example | ||
arr | arr = [1,2,3]; | ||
[arr, 0] | [arr, 0] call KK_fnc_unshift; // both arr and return of function are [0,1,2,3] | ||
</ | </sqf> | ||
}} | |||
{{Note | |||
|user= Killzone_Kid | |||
|timestamp= 20150521152100 | |||
Array "insert" implementation using [[append]], much faster alternative to [[BIS_fnc_arrayInsert]]: | |text= Array "insert" implementation using [[append]], much faster alternative to [[BIS_fnc_arrayInsert]]: | ||
< | <sqf> | ||
KK_fnc_insert = { | |||
_arr | private ["_arr", "_i", "_res"]; | ||
_i | _arr = _this select 0; | ||
_res | _i = _this select 2; | ||
_res | _res = []; | ||
_res | _res append (_arr select [0, _i]); | ||
_res | _res append (_this select 1); | ||
_res | _res append (_arr select [_i, count _arr - _i]); | ||
_res; | |||
}; | }; | ||
// Example | // Example | ||
arr | arr = [1,2,3,4]; | ||
[arr, ["a","b"], 2] | [arr, ["a","b"], 2] call KK_fnc_insert; // [1,2,"a","b",3,4] | ||
</sqf> | |||
}} | |||
{{Note | |||
|user= Killzone_Kid | |||
|timestamp= 20150521155200 | |||
A faster alternative to [[BIS_fnc_arrayPushStack]] using [[append]]: | |text= A faster alternative to [[BIS_fnc_arrayPushStack]] using [[append]]: | ||
< | <sqf> | ||
_this | KK_fnc_pushStack = { | ||
_this | _this select 0 append (_this select 1); | ||
_this select 0 | |||
}; | }; | ||
// Example | // Example | ||
arr | arr = [1,2,3]; | ||
[arr,[4,5,6]] | [arr, [4,5,6]] call KK_fnc_pushStack; // both arr and function return are [1,2,3,4,5,6] | ||
</ | </sqf> | ||
}} | |||
Latest revision as of 18:52, 9 August 2022
Description
- Description:
- Appends array2 to the back of array1 modifying array1. See insert for an "appendUnique" equivalent.
- Groups:
- Arrays
Syntax
Examples
- Example 1:
Additional Information
- See also:
- set pushBack pushBackUnique insert + apply select resize reverse count deleteAt deleteRange
Notes
-
Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
- Posted on Mar 09, 2015 - 00:41 (UTC)
-
is roughly 1.2× faster (depending on array size) than (Averaged over 10.000 iterations with two identical arrays containing the numbers 0 through 9)_array1 append _array2;
The larger the arrays to append, the faster append is as it does not create a new array, which happens with array addition.
- Posted on May 21, 2015 - 10:27 (UTC)
- Array "unshift" implementation using append, a faster alternative to BIS_fnc_arrayUnShift:
- Posted on May 21, 2015 - 15:21 (UTC)
-
Array "insert" implementation using append, much faster alternative to BIS_fnc_arrayInsert:
KK_fnc_insert = { private ["_arr", "_i", "_res"]; _arr = _this select 0; _i = _this select 2; _res = []; _res append (_arr select [0, _i]); _res append (_this select 1); _res append (_arr select [_i, count _arr - _i]); _res; }; // Example arr = [1,2,3,4]; [arr, ["a","b"], 2] call KK_fnc_insert; // [1,2,"a","b",3,4]
- Posted on May 21, 2015 - 15:52 (UTC)
- A faster alternative to BIS_fnc_arrayPushStack using append: