merge: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) (Add more examples thanks to killerswin2 on Discord) |
Lou Montana (talk | contribs) m (Some wiki formatting) |
||
Line 29: | Line 29: | ||
|x2= <sqf> | |x2= <sqf> | ||
private | private _hashmap1 = ["cow", "cat", "chicken"] createHashMapFromArray [100, 200, 200]; | ||
private _hashmap2 = | 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> | </sqf> | ||
|x3= <sqf> | |x3= <sqf> | ||
private | private _hashmap1 = ["cow", "cat", "chicken"] createHashMapFromArray [100, 200, 200]; | ||
private _hashmap2 = | 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> | </sqf> | ||
|x4= <sqf> | |x4= <sqf> | ||
private | private _hashmap1 = ["cow", "cat", "chicken"] createHashMapFromArray [100, 200, 200]; | ||
private _hashmap2 = | 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> | </sqf> | ||
|seealso= [[insert]] [[set]] | |seealso= [[insert]] [[set]] | ||
}} | }} |
Revision as of 19:59, 5 July 2023
Description
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
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