UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SlateElementSortedArray.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Algo/BinarySearch.h"
6#include "Containers/Array.h"
8
12template <typename InElementType, typename InSortPredicate = TLess<>>
14{
16 DataType Data;
17
18public:
19 using SizeType = typename DataType::SizeType;
23
24public:
27 {
28 return Data.GetData()[Index];
29 }
30
31public:
37
40 {
41 return Data.IsValidIndex(Index);
42 }
43
46 {
47 return Data.Num();
48 }
49
50public:
58 {
59 return Algo::BinarySearch(Data, Item, SortPredicate());
60 }
61
68 bool Contains(ElementParamType Item) const
69 {
70 return Find(Item) != INDEX_NONE;
71 }
72
77 {
78 const SizeType FoundIndex = Algo::LowerBound(Data, Value, SortPredicate());
79 return Data.IsValidIndex(FoundIndex) ? FoundIndex : INDEX_NONE;
80 }
81
86 {
87 const SizeType FoundIndex = Algo::UpperBound(Data, Value, SortPredicate());
88 return Data.IsValidIndex(FoundIndex) ? FoundIndex : INDEX_NONE;
89 }
90
91public:
99 {
101 if (LowerBoundIndex >= Num() || SortPredicate()(Item, Data.GetData()[LowerBoundIndex]))
102 {
103 return Data.Insert(Item, LowerBoundIndex);
104 }
105 return 0;
106 }
107
116 {
117 return Data.Add(Item);
118 }
119
127 {
128 SizeType Index = Find(Item);
129 if (Index != INDEX_NONE)
130 {
131 Data.RemoveAt(Index, EAllowShrinking::No);
132 return 1;
133 }
134 return 0;
135 }
136
145 template <typename CountType>
150
152 void Sort()
153 {
154 Algo::Sort(Data, SortPredicate());
155 }
156
157public:
163 FORCEINLINE RangedForConstIteratorType begin() const { return Data.begin(); }
164 FORCEINLINE RangedForConstIteratorType end() const { return Data.end(); }
165};
#define FORCEINLINE
Definition AndroidPlatform.h:140
@ INDEX_NONE
Definition CoreMiscDefines.h:150
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
TCheckedPointerIterator< const ElementType, SizeType, false > RangedForConstIteratorType
Definition Array.h:3372
typename InAllocatorType::SizeType SizeType
Definition Array.h:675
Definition SlateElementSortedArray.h:14
SizeType Find(ElementParamType Item) const
Definition SlateElementSortedArray.h:57
InElementType ElementType
Definition SlateElementSortedArray.h:20
bool Contains(ElementParamType Item) const
Definition SlateElementSortedArray.h:68
FORCEINLINE RangedForConstIteratorType begin() const
Definition SlateElementSortedArray.h:163
FORCEINLINE RangedForConstIteratorType end() const
Definition SlateElementSortedArray.h:164
FORCEINLINE SizeType Num() const
Definition SlateElementSortedArray.h:45
SizeType FindLowerBound(ElementParamType Value) const
Definition SlateElementSortedArray.h:76
FORCEINLINE void RemoveAt(SizeType Index, CountType Count)
Definition SlateElementSortedArray.h:146
typename DataType::RangedForConstIteratorType RangedForConstIteratorType
Definition SlateElementSortedArray.h:162
FORCEINLINE void Empty(SizeType ExpectedNumElements=0)
Definition SlateElementSortedArray.h:33
TLess<> SortPredicate
Definition SlateElementSortedArray.h:22
FORCEINLINE ElementParamType operator[](SizeType Index) const
Definition SlateElementSortedArray.h:26
void Sort()
Definition SlateElementSortedArray.h:152
typename TCallTraits< ElementType >::ParamType ElementParamType
Definition SlateElementSortedArray.h:21
SizeType RemoveSingle(ElementParamType Item)
Definition SlateElementSortedArray.h:126
SizeType FindUpperBound(ElementParamType Value) const
Definition SlateElementSortedArray.h:85
typename DataType::SizeType SizeType
Definition SlateElementSortedArray.h:19
FORCEINLINE bool IsValidIndex(SizeType Index) const
Definition SlateElementSortedArray.h:39
FORCEINLINE SizeType AddUnsorted(ElementType Item)
Definition SlateElementSortedArray.h:115
SizeType InsertUnique(ElementParamType Item)
Definition SlateElementSortedArray.h:98
UE_REWRITE void Sort(RangeType &&Range)
Definition Sort.h:16
UE_REWRITE auto LowerBound(const RangeType &Range, const ValueType &Value, SortPredicateType SortPredicate) -> decltype(GetNum(Range))
Definition BinarySearch.h:92
auto BinarySearch(const RangeType &Range, const ValueType &Value, SortPredicateType SortPredicate) -> decltype(GetNum(Range))
Definition BinarySearch.h:173
UE_REWRITE auto UpperBound(const RangeType &Range, const ValueType &Value, SortPredicateType SortPredicate) -> decltype(GetNum(Range))
Definition BinarySearch.h:133
U16 Index
Definition radfft.cpp:71
TCallTraitsParamTypeHelper< T, PassByValue >::ParamType ParamType
Definition UnrealTypeTraits.h:275
Definition Less.h:19