Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
LegacySort.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Templates/IdentityFunctor.h"
6#include "Templates/Invoke.h"
7#include "Templates/Less.h"
8#include "Templates/UnrealTemplate.h" // For GetData, GetNum
9
10
11namespace AlgoImpl
12{
13 /**
14 * Sort elements using user defined predicate class. The sort is unstable, meaning that the ordering of equal items is not necessarily preserved.
15 * This is the internal sorting function used by Sort overrides.
16 * This used to be Algo::Sort and is now considered legacy.
17 *
18 * @param First pointer to the first element to sort
19 * @param Num the number of items to sort
20 * @param Predicate predicate class
21 */
22 template <typename T, typename ProjectionType, typename PredicateType>
23 void LegacySortInternal(T* First, int32 Num, ProjectionType Projection, PredicateType Predicate)
24 {
25 struct FStack
26 {
27 T* Min;
28 T* Max;
29 };
30
31 if( Num < 2 )
32 {
33 return;
34 }
37 {
39 Loop:
41 if( Count <= 8 )
42 {
43 // Use simple bubble-sort.
44 while( Current.Max > Current.Min )
45 {
46 T *Max, *Item;
48 {
50 {
51 Max = Item;
52 }
53 }
54 Swap( *Max, *Current.Max-- );
55 }
56 }
57 else
58 {
59 // Grab middle element so sort doesn't exhibit worst-cast behavior with presorted lists.
60 Swap( Current.Min[Count/2], Current.Min[0] );
61
62 // Divide list into two halves, one with items <=Current.Min, the other with items >Current.Max.
64 Inner.Max = Current.Max+1;
65 for( ; ; )
66 {
69 if( Inner.Min>Inner.Max )
70 {
71 break;
72 }
73 Swap( *Inner.Min, *Inner.Max );
74 }
75 Swap( *Current.Min, *Inner.Max );
76
77 // Save big half and recurse with small half.
79 {
80 if( Current.Min+1 < Inner.Max )
81 {
83 StackTop->Max = Inner.Max - 1;
84 StackTop++;
85 }
86 if( Current.Max>Inner.Min )
87 {
89 goto Loop;
90 }
91 }
92 else
93 {
94 if( Current.Max>Inner.Min )
95 {
98 StackTop++;
99 }
100 if( Current.Min+1<Inner.Max )
101 {
102 Current.Max = Inner.Max - 1;
103 goto Loop;
104 }
105 }
106 }
107 }
108 }
109}
110
111namespace Algo
112{
113 /**
114 * Sort a range of elements using its operator<. The sort is unstable.
115 * This used to be Algo::Sort and is now considered legacy.
116 *
117 * @param Range The range to sort.
118 */
119 template <typename RangeType>
120 FORCEINLINE void LegacySort(RangeType&& Range)
121 {
123 }
124
125 /**
126 * Sort a range of elements using a user-defined predicate class. The sort is unstable.
127 * This used to be Algo::Sort and is now considered legacy.
128 *
129 * @param Range The range to sort.
130 * @param Predicate A binary predicate object used to specify if one element should precede another.
131 */
132 template <typename RangeType, typename PredicateType>
133 FORCEINLINE void LegacySort(RangeType&& Range, PredicateType Pred)
134 {
136 }
137
138 /**
139 * Sort a range of elements by a projection using the projection's operator<. The sort is unstable.
140 * This used to be Algo::Sort and is now considered legacy.
141 *
142 * @param Range The range to sort.
143 * @param Proj The projection to sort by when applied to the element.
144 */
145 template <typename RangeType, typename ProjectionType>
146 FORCEINLINE void LegacySortBy(RangeType&& Range, ProjectionType Proj)
147 {
149 }
150
151 /**
152 * Sort a range of elements by a projection using a user-defined predicate class. The sort is unstable.
153 * This used to be Algo::Sort and is now considered legacy.
154 *
155 * @param Range The range to sort.
156 * @param Proj The projection to sort by when applied to the element.
157 * @param Predicate A binary predicate object, applied to the projection, used to specify if one element should precede another.
158 */
159 template <typename RangeType, typename ProjectionType, typename PredicateType>
160 FORCEINLINE void LegacySortBy(RangeType&& Range, ProjectionType Proj, PredicateType Pred)
161 {
163 }
164}
#define FORCEINLINE
Definition Platform.h:644
Definition Heapify.h:12
FORCEINLINE void LegacySortBy(RangeType &&Range, ProjectionType Proj)
Definition LegacySort.h:146
FORCEINLINE void LegacySort(RangeType &&Range)
Definition LegacySort.h:120
FORCEINLINE void LegacySortBy(RangeType &&Range, ProjectionType Proj, PredicateType Pred)
Definition LegacySort.h:160
FORCEINLINE void LegacySort(RangeType &&Range, PredicateType Pred)
Definition LegacySort.h:133
void LegacySortInternal(T *First, int32 Num, ProjectionType Projection, PredicateType Predicate)
Definition LegacySort.h:23