30 static int GetWeightedIndex(notnull array<float> weights,
float value01)
32 if (weights.IsEmpty())
35 if (value01 < 0 || value01 > 1)
36 value01 = Math.Mod(value01, 1);
39 for (
int i, count = weights.Count(); i < count; i++)
41 probabilitySum += weights[i];
45 probabilitySum *= value01;
47 for (
int i, count = weights.Count(); i < count; i++)
50 if (add > probabilitySum)
61 class SCR_ArrayHelperT<Class T>
71 foreach (T sourceRef : source)
73 destination.Insert(sourceRef);
81 static array<T> GetCopy(array<T> source)
95 static array<ref T> GetCopy(array<ref T> source)
100 array<ref T> result = {};
101 foreach (T sourceRef : source)
103 result.Insert(sourceRef);
114 static void Intersect(notnull array<T> array1, notnull array<T> array2, notnull out array<T> result)
117 int count1 = array1.Count();
118 int count2 = array2.Count();
121 for (
int i = array2.Count() - 1; i >= 0; i--)
123 if (array1.Contains(array2[i]))
124 result.Insert(array2[i]);
129 for (
int i = array1.Count() - 1; i >= 0; i--)
131 if (array2.Contains(array1[i]))
132 result.Insert(array1[i]);
143 static void Intersect(notnull array<ref T> array1, notnull array<ref T> array2, notnull out array<ref T> result)
146 int count1 = array1.Count();
147 int count2 = array2.Count();
150 for (
int i = array2.Count() - 1; i >= 0; i--)
152 if (array1.Contains(array2[i]))
153 result.Insert(array2[i]);
158 for (
int i = array1.Count() - 1; i >= 0; i--)
160 if (array2.Contains(array1[i]))
161 result.Insert(array1[i]);
170 static void RemoveDuplicates(notnull inout array<T> items)
172 for (
int i = items.Count() - 1; i >= 0; --i)
174 if (items.Find(items[i]) != i)
175 items.RemoveOrdered(i);
183 static void RemoveDuplicates(notnull inout array<ref T> items)
185 for (
int i = items.Count() - 1; i >= 0; --i)
187 if (items.Find(items[i]) != i)
188 items.RemoveOrdered(i);
202 static void Reverse(notnull inout array<T> items)
204 int itemsCount = items.Count();
208 int flooredMiddle = itemsCount * 0.5;
226 for (
int i; i < flooredMiddle; i++)
228 items.SwapItems(i, itemsCount - i);
242 static void Reverse(notnull inout array<ref T> items)
244 int itemsCount = items.Count();
248 int flooredMiddle = itemsCount * 0.5;
266 for (
int i; i < flooredMiddle; i++)
268 items.SwapItems(i, itemsCount - i);
282 static void Shuffle(notnull inout array<T> items,
int shuffles = 1)
284 if (items.Count() < 2)
296 for (
int i = 0, count = items.Count(); i < count; i++)
298 int index1 = Math.RandomInt(0, count);
299 int index2 = Math.RandomInt(0, count);
300 if (index1 != index2)
301 items.SwapItems(index1, index2);
318 static void Shuffle(notnull inout array<ref T> items,
int shuffles = 1)
320 if (items.Count() < 2)
332 for (
int i = 0, count = items.Count(); i < count; i++)
334 int index1 = Math.RandomInt(0, count);
335 int index2 = Math.RandomInt(0, count);
336 if (index1 != index2)
337 items.SwapItems(index1, index2);