Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_MapHelper.c
Go to the documentation of this file.
4class SCR_MapHelperT<Class T, Class U>
5{
6 //------------------------------------------------------------------------------------------------
11 // NATIVE-NATIVE version
12 static bool AreEqual(notnull map<T, U> map1, notnull map<T, U> map2)
13 {
14 if (map1.Count() != map2.Count())
15 return false;
16
17 U tmp;
18 foreach (T index, U value : map1)
19 {
20 if (!map2.Find(index, tmp) || tmp != value)
21 return false;
22 }
23
24 return true;
25 }
26
27 //------------------------------------------------------------------------------------------------
32 // NATIVE-REFERENCE version
33 static bool AreEqual(notnull map<T, ref U> map1, notnull map<T, ref U> map2)
34 {
35 if (map1.Count() != map2.Count())
36 return false;
37
38 U tmp;
39 foreach (T index, U value : map1)
40 {
41 if (!map2.Find(index, tmp) || tmp != value)
42 return false;
43 }
44
45 return true;
46 }
47
48 //------------------------------------------------------------------------------------------------
53 // REFERENCE-NATIVE version
54 static bool AreEqual(notnull map<ref T, U> map1, notnull map<ref T, U> map2)
55 {
56 if (map1.Count() != map2.Count())
57 return false;
58
59 U tmp;
60 foreach (T index, U value : map1)
61 {
62 if (!map2.Find(index, tmp) || tmp != value)
63 return false;
64 }
65
66 return true;
67 }
68
69 //------------------------------------------------------------------------------------------------
74 // REFERENCE-REFERENCE version
75 static bool AreEqual(notnull map<ref T, ref U> map1, notnull map<ref T, ref U> map2)
76 {
77 if (map1.Count() != map2.Count())
78 return false;
79
80 U tmp;
81 foreach (T index, U value : map1)
82 {
83 if (!map2.Find(index, tmp) || tmp != value)
84 return false;
85 }
86
87 return true;
88 }
89
90 //------------------------------------------------------------------------------------------------
95 // NATIVE-NATIVE version
96 static map<T, U> ArraysToMap(notnull array<T> indices, notnull array<U> values)
97 {
98 map<T, U> result = new map<T, U>();
99 for (int i, count = Math.Min(indices.Count(), values.Count()); i < count; i++)
100 {
101 result.Insert(indices[i], values[i]);
102 }
103
104 return result;
105 }
106
107 //------------------------------------------------------------------------------------------------
112 // NATIVE-REFERENCE version
113 static map<T, ref U> ArraysToMap(notnull array<T> indices, notnull array<ref U> values)
114 {
115 map<T, ref U> result = new map<T, ref U>();
116 for (int i, count = Math.Min(indices.Count(), values.Count()); i < count; i++)
117 {
118 result.Insert(indices[i], values[i]);
119 }
120
121 return result;
122 }
123
124 //------------------------------------------------------------------------------------------------
129 // REFERENCE-NATIVE version
130 static map<ref T, U> ArraysToMap(notnull array<ref T> indices, notnull array<U> values)
131 {
132 map<ref T, U> result = new map<ref T, U>();
133 for (int i, count = Math.Min(indices.Count(), values.Count()); i < count; i++)
134 {
135 result.Insert(indices[i], values[i]);
136 }
137
138 return result;
139 }
140
141 //------------------------------------------------------------------------------------------------
146 // REFERENCE-REFERENCE version
147 static map<ref T, ref U> ArraysToMap(notnull array<ref T> indices, notnull array<ref U> values)
148 {
150 for (int i, count = Math.Min(indices.Count(), values.Count()); i < count; i++)
151 {
152 result.Insert(indices[i], values[i]);
153 }
154
155 return result;
156 }
157
158 //------------------------------------------------------------------------------------------------
161 // NATIVE-NATIVE version
162 static array<T> GetKeys(notnull map<T, U> input)
163 {
164 array<T> result = {};
165 foreach (T key, U value : input)
166 {
167 result.Insert(key);
168 }
169
170 return result;
171 }
172
173 //------------------------------------------------------------------------------------------------
176 // NATIVE-REFERENCE version
177 static array<T> GetKeys(notnull map<T, ref U> input)
178 {
179 array<T> result = {};
180 foreach (T key, U value : input)
181 {
182 result.Insert(key);
183 }
184
185 return result;
186 }
187
188 //------------------------------------------------------------------------------------------------
191 // REFERENCE-NATIVE version
192 static array<ref T> GetKeys(notnull map<ref T, U> input)
193 {
194 array<ref T> result = {};
195 foreach (T key, U value : input)
196 {
197 result.Insert(key);
198 }
199
200 return result;
201 }
202
203 //------------------------------------------------------------------------------------------------
206 // REFERENCE-REFERENCE version
207 static array<ref T> GetKeys(notnull map<ref T, ref U> input)
208 {
209 array<ref T> result = {};
210 foreach (T key, U value : input)
211 {
212 result.Insert(key);
213 }
214
215 return result;
216 }
217
218 //------------------------------------------------------------------------------------------------
221 // NATIVE-NATIVE version
222 static array<U> GetElements(notnull map<T, U> input)
223 {
224 array<U> result = {};
225 for (int i = 0, count = input.Count(); i < count; i++)
226 {
227 result.Insert(input.GetElement(i));
228 }
229
230 return result;
231 }
232
233 //------------------------------------------------------------------------------------------------
236 // NATIVE-REFERENCE version
237 static array<ref U> GetElements(notnull map<T, ref U> input)
238 {
239 array<ref U> result = {};
240 foreach (T key, U value : input)
241 {
242 result.Insert(value);
243 }
244
245 return result;
246 }
247
248 //------------------------------------------------------------------------------------------------
251 // REFERENCE-NATIVE version
252 static array<U> GetElements(notnull map<ref T, U> input)
253 {
254 array<U> result = {};
255 foreach (T key, U value : input)
256 {
257 result.Insert(value);
258 }
259
260 return result;
261 }
262
263 //------------------------------------------------------------------------------------------------
266 // REFERENCE-REFERENCE version
267 static array<ref U> GetElements(notnull map<ref T, ref U> input)
268 {
269 array<ref U> result = {};
270 foreach (T key, U value : input)
271 {
272 result.Insert(value);
273 }
274
275 return result;
276 }
277
278 //------------------------------------------------------------------------------------------------
283 // NATIVE-NATIVE version
284 static void InsertAll(notnull map<T, U> receiver, notnull map<T, U> sender, bool allowOverride = true)
285 {
286 if (allowOverride) // done so for performance
287 {
288 foreach (T key, U value : sender)
289 {
290 receiver.Set(key, value);
291 }
292 }
293 else
294 {
295 foreach (T key, U value : sender)
296 {
297 receiver.Insert(key, value);
298 }
299 }
300 }
301
302 //------------------------------------------------------------------------------------------------
307 // NATIVE-REFERENCE version
308 static void InsertAll(notnull map<T, ref U> receiver, notnull map<T, ref U> sender, bool allowOverride = true)
309 {
310 if (allowOverride) // done so for performance
311 {
312 foreach (T key, U value : sender)
313 {
314 receiver.Insert(key, value);
315 }
316 }
317 else
318 {
319 foreach (T key, U value : sender)
320 {
321 if (!receiver.Contains(key))
322 receiver.Insert(key, value);
323 }
324 }
325 }
326
327 //------------------------------------------------------------------------------------------------
332 // REFERENCE-NATIVE version
333 static void InsertAll(notnull map<ref T, U> receiver, notnull map<ref T, U> sender, bool allowOverride = true)
334 {
335 if (allowOverride) // done so for performance
336 {
337 foreach (T key, U value : sender)
338 {
339 receiver.Insert(key, value);
340 }
341 }
342 else
343 {
344 foreach (T key, U value : sender)
345 {
346 if (!receiver.Contains(key))
347 receiver.Insert(key, value);
348 }
349 }
350 }
351
352 //------------------------------------------------------------------------------------------------
357 // REFERENCE-REFERENCE version
358 static void InsertAll(notnull map<ref T, ref U> receiver, notnull map<ref T, ref U> sender, bool allowOverride = true)
359 {
360 if (allowOverride) // done so for performance
361 {
362 foreach (T key, U value : sender)
363 {
364 receiver.Insert(key, value);
365 }
366 }
367 else
368 {
369 foreach (T key, U value : sender)
370 {
371 if (!receiver.Contains(key))
372 receiver.Insert(key, value);
373 }
374 }
375 }
376}
377
378class SCR_MapHelper<Class T, Class U>
379{
380 //------------------------------------------------------------------------------------------------
384 static T GetKeyByValue(notnull map<T, U> input, U value)
385 {
386 for (int i, count = input.Count(); i < count; i++)
387 {
388 if (input.GetElement(i) == value)
389 {
390 return input.GetKey(i);
391 break;
392 }
393 }
394
395 const T result;
396 return result;
397 }
398
399 //------------------------------------------------------------------------------------------------
405 static bool ReplaceKey(notnull map<T, U> input, T oldKey, T newKey)
406 {
407 if (!input.Contains(oldKey))
408 return false;
409
410 input.Set(newKey, input.Get(oldKey));
411 input.Remove(oldKey);
412 return true;
413 }
414}
class SCR_ArrayHelper AreEqual(notnull array< T > array1, notnull array< T > array2)
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
class SCR_MapHelperT< Class T, Class U > GetKeyByValue(notnull map< T, U > input, U value)
class SCR_MapHelperT< Class T, Class U > T
Super root of all classes in Enforce script.
Definition Types.c:35
Definition Math.c:13
Definition Types.c:486
void InsertAll(notnull array< T > from)
Definition Types.c:250