merge: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(Created page)
 
mNo edit summary
 
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{RV|type=command
{{RV|type=command


|game1= arma3dev
|game1= arma3
 
|version1= 2.02
|version1= 2.04


|gr1= HashMap
|gr1= HashMap


|descr= Merges two [[HashMap|HashMaps]].
|descr= Merges two [[HashMap]]s.


|s1= map1 [[merge]] map2
|s1= hashMap1 [[merge]] hashMap2


|p1= '''map1''': [[HashMap]] - This HashMap will be modified.
|p1= hashMap1: [[HashMap]] - this HashMap will be modified


|p2= '''map2''': [[HashMap]] - All key-value pairs from this HashMap are added to '''map1'''. If a key from '''map2''' already exists in '''map1''', then its value is overwritten with the corresponding value from '''map2'''.
|p2= hashMap2: [[HashMap]] - all key-value pairs from this HashMap are added to ''hashMap1''. If a key from ''hashMap2'' already exists in ''hashMap1'', it doesn't overwrite the value in ''hashMap1''.


|r1= [[Nothing]]
|r1= [[Nothing]]


|s2= map1 [[merge]] [map2, overwriteExisting]
|s2= hashMap1 [[merge]] [hashMap2, overwriteExisting]


|p21= '''map1''': [[HashMap]] - This HashMap will be modified.
|p21= hashMap1: [[HashMap]] - this HashMap will be modified


|p22= '''map2''': [[HashMap]] - All key-value pairs from this HashMap are added to '''map1'''.
|p22= hashMap2: [[HashMap]] - all key-value pairs from this HashMap are added to ''hashMap1''


|p23= '''overwriteExisting''' (Optional, default: [[false]]): [[Boolean]] - If [[true]], keys from '''map1''' that also exist in '''map2''' are overwritten. [[merge]] is faster when this parameter is set to [[true]].
|p23= overwriteExisting: [[Boolean]] - (Optional, default [[false]]) if [[true]], keys from ''hashMap1'' that also exist in ''hashMap2'' are overwritten. When set to [[true]], merging is faster


|r2= [[Nothing]]
|r2= [[Nothing]]


|x1= <code>_hashMap [[merge]] _otherHashMap;</code>
|x1= <sqf>_hashMap merge _otherHashMap;</sqf>
 
|x2= <sqf>
private _hashmap1 = ["cow", "cat", "chicken"] createHashMapFromArray [100, 200, 200];
private _hashmap2 = ["cow", "cat", "chicken", "camel"] createHashMapFromArray [150, 300, 400, 800];
_hashmap1 merge _hashmap2; // _hashmap is [["cow",100],["cat",200],["chicken",200],["camel",800]]
</sqf>
 
|x3= <sqf>
private _hashmap1 = ["cow", "cat", "chicken"] createHashMapFromArray [100, 200, 200];
private _hashmap2 = ["cow", "cat", "chicken", "camel"] createHashMapFromArray [150, 300, 400, 800];
_hashmap1 merge [_hashmap2, true]; // _hashmap is [["cow",150],["cat",300],["chicken",400],["camel",800]]
</sqf>
 
|x4= <sqf>
private _hashmap1 = ["cow", "cat", "chicken"] createHashMapFromArray [100, 200, 200];
private _hashmap2 = ["cow", "cat", "chicken", "camel"] createHashMapFromArray [150, 300, 400, 800];
_hashmap1 merge [_hashmap2, false]; // _hashmap is [["cow",100],["cat",200],["chicken",200],["camel",800]] as Syntax 1
</sqf>


|seealso= [[HashMap]]
|seealso= [[insert]] [[set]]
}}
}}

Latest revision as of 21:05, 28 September 2023

Hover & click on the images for description

Description

Description:
Merges two HashMaps.
Groups:
HashMap

Syntax

Syntax:
hashMap1 merge hashMap2
Parameters:
hashMap1: HashMap - this HashMap will be modified
hashMap2: HashMap - all key-value pairs from this HashMap are added to hashMap1. If a key from hashMap2 already exists in hashMap1, it doesn't overwrite the value in hashMap1.
Return Value:
Nothing

Alternative Syntax

Syntax:
hashMap1 merge [hashMap2, overwriteExisting]
Parameters:
hashMap1: HashMap - this HashMap will be modified
hashMap2: HashMap - all key-value pairs from this HashMap are added to hashMap1
overwriteExisting: Boolean - (Optional, default false) if true, keys from hashMap1 that also exist in hashMap2 are overwritten. When set to true, merging is faster
Return Value:
Nothing

Examples

Example 1:
_hashMap merge _otherHashMap;
Example 2:
private _hashmap1 = ["cow", "cat", "chicken"] createHashMapFromArray [100, 200, 200]; private _hashmap2 = ["cow", "cat", "chicken", "camel"] createHashMapFromArray [150, 300, 400, 800]; _hashmap1 merge _hashmap2; // _hashmap is [["cow",100],["cat",200],["chicken",200],["camel",800]]
Example 3:
private _hashmap1 = ["cow", "cat", "chicken"] createHashMapFromArray [100, 200, 200]; private _hashmap2 = ["cow", "cat", "chicken", "camel"] createHashMapFromArray [150, 300, 400, 800]; _hashmap1 merge [_hashmap2, true]; // _hashmap is [["cow",150],["cat",300],["chicken",400],["camel",800]]
Example 4:
private _hashmap1 = ["cow", "cat", "chicken"] createHashMapFromArray [100, 200, 200]; private _hashmap2 = ["cow", "cat", "chicken", "camel"] createHashMapFromArray [150, 300, 400, 800]; _hashmap1 merge [_hashmap2, false]; // _hashmap is [["cow",100],["cat",200],["chicken",200],["camel",800]] as Syntax 1

Additional Information

See also:
insert set

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