Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ PickPivotAndPartition() [1/2]

static int System.Collections.Generic.ArraySortHelper< TKey, TValue >.PickPivotAndPartition ( Span< T > keys,
Comparison< T > comparer )
inlinestaticprivate

Definition at line 163 of file ArraySortHelper.cs.

164 {
165 int num = keys.Length - 1;
166 int num2 = num >> 1;
167 SwapIfGreater(keys, comparer, 0, num2);
168 SwapIfGreater(keys, comparer, 0, num);
169 SwapIfGreater(keys, comparer, num2, num);
170 T val = keys[num2];
171 Swap(keys, num2, num - 1);
172 int num3 = 0;
173 int num4 = num - 1;
174 while (num3 < num4)
175 {
176 while (comparer(keys[++num3], val) < 0)
177 {
178 }
179 while (comparer(val, keys[--num4]) < 0)
180 {
181 }
182 if (num3 >= num4)
183 {
184 break;
185 }
186 Swap(keys, num3, num4);
187 }
188 if (num3 != num - 1)
189 {
190 Swap(keys, num3, num - 1);
191 }
192 return num3;
193 }
static void Swap(Span< T > a, int i, int j)
static void SwapIfGreater(Span< T > keys, Comparison< T > comparer, int i, int j)

References System.comparer, System.keys, System.Collections.Generic.ArraySortHelper< TKey, TValue >.Swap(), and System.Collections.Generic.ArraySortHelper< TKey, TValue >.SwapIfGreater().

Referenced by System.Collections.Generic.ArraySortHelper< TKey, TValue >.IntroSort(), and System.Collections.Generic.ArraySortHelper< TKey, TValue >.IntroSort().