Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
IsSorted.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Templates/IdentityFunctor.h"
7#include "Templates/Invoke.h"
8#include "Templates/Less.h"
9#include "Templates/UnrealTemplate.h" // For GetData, GetNum, MoveTemp
10
11
12namespace AlgoImpl
13{
14 template <typename T, typename IndexType, typename ProjectionType, typename PredType>
15 bool IsSortedBy(const T* Range, IndexType RangeSize, ProjectionType Proj, PredType Pred)
16 {
17 if (RangeSize == 0)
18 {
19 return true;
20 }
21
22 // When comparing N elements, we do N-1 comparisons
23 --RangeSize;
24
25 const T* Next = Range + 1;
26 for (;;)
27 {
28 if (RangeSize == 0)
29 {
30 return true;
31 }
32
33 auto&& Ref1 = Invoke(Proj, *Next);
34 auto&& Ref2 = Invoke(Proj, *Range);
35 if (Invoke(Pred, Ref1, Ref2))
36 {
37 return false;
38 }
39
40 ++Range;
41 ++Next;
42 --RangeSize;
43 }
44 }
45
46 template <typename T>
47 struct TLess
48 {
49 FORCEINLINE bool operator()(const T& Lhs, const T& Rhs) const
50 {
51 return Lhs < Rhs;
52 }
53 };
54}
55
56namespace Algo
57{
58 /**
59 * Tests if a range is sorted by its element type's operator<.
60 *
61 * @param Range The container to test for being sorted.
62 *
63 * @return true if the range is sorted, false otherwise.
64 */
65 template <typename RangeType>
66 FORCEINLINE bool IsSorted(const RangeType& Range)
67 {
69 }
70
71 /**
72 * Tests if a range is sorted by a user-defined predicate.
73 *
74 * @param Range The container to test for being sorted.
75 * @param Pred A binary sorting predicate which describes the ordering of the elements in the array.
76 *
77 * @return true if the range is sorted, false otherwise.
78 */
79 template <typename RangeType, typename PredType>
80 FORCEINLINE bool IsSorted(const RangeType& Range, PredType Pred)
81 {
83 }
84
85 /**
86 * Tests if a range is sorted by a projection of the element type, using the projection's operator<.
87 *
88 * @param Range The container to test for being sorted.
89 *
90 * @return true if the range is sorted, false otherwise.
91 */
92 template <typename RangeType, typename ProjectionType>
93 FORCEINLINE bool IsSortedBy(const RangeType& Range, ProjectionType Projection)
94 {
96 }
97
98 /**
99 * Tests if a range is sorted by a projection of the element type, using a user-defined predicate on the projection.
100 *
101 * @param Range The container to test for being sorted.
102 * @param Pred A binary sorting predicate which describes the ordering of the elements in the array.
103 *
104 * @return true if the range is sorted, false otherwise.
105 */
106 template <typename RangeType, typename ProjectionType, typename PredType>
107 FORCEINLINE bool IsSortedBy(const RangeType& Range, ProjectionType Projection, PredType Pred)
108 {
110 }
111}
#define FORCEINLINE
Definition Platform.h:644
Definition Heapify.h:12
FORCEINLINE bool IsSorted(const RangeType &Range, PredType Pred)
Definition IsSorted.h:80
FORCEINLINE bool IsSortedBy(const RangeType &Range, ProjectionType Projection, PredType Pred)
Definition IsSorted.h:107
FORCEINLINE bool IsSortedBy(const RangeType &Range, ProjectionType Projection)
Definition IsSorted.h:93
FORCEINLINE bool IsSorted(const RangeType &Range)
Definition IsSorted.h:66
bool IsSortedBy(const T *Range, IndexType RangeSize, ProjectionType Proj, PredType Pred)
Definition IsSorted.h:15
FORCEINLINE bool operator()(const T &Lhs, const T &Rhs) const
Definition IsSorted.h:49