18template<
typename KeyType,
typename IndexType = u
int32 >
22 static_assert(std::is_unsigned_v<IndexType>,
"FBinaryHeap only supports unsigned index types");
74template<
typename KeyType,
typename IndexType >
80template<
typename KeyType,
typename IndexType >
93template<
typename KeyType,
typename IndexType >
96 HeapNum =
Other.HeapNum;
97 HeapSize =
Other.HeapSize;
98 IndexSize =
Other.IndexSize;
102 HeapIndexes =
Other.HeapIndexes;
104 Other.ResetInternal();
107template<
typename KeyType,
typename IndexType >
113template<
typename KeyType,
typename IndexType >
120template<
typename KeyType,
typename IndexType >
125 delete[] HeapIndexes;
130template<
typename KeyType,
typename IndexType >
159template<
typename KeyType,
typename IndexType >
169 delete[] HeapIndexes;
172 HeapIndexes =
nullptr;
184 for(
uint32 i = 0; i < IndexSize; i++ )
190 delete[] HeapIndexes;
203template<
typename KeyType,
typename IndexType >
217template<
typename KeyType,
typename IndexType >
220 if (
Index >= IndexSize)
224 return HeapIndexes[
Index ] != (IndexType)-1;
227template<
typename KeyType,
typename IndexType >
231 return Keys[
Index ];
234template<
typename KeyType,
typename IndexType >
241template<
typename KeyType,
typename IndexType >
249template<
typename KeyType,
typename IndexType >
258 HeapIndexes[
Heap[0] ] = 0;
259 HeapIndexes[
Index ] = (IndexType)-1;
264template<
typename KeyType,
typename IndexType >
267 if( HeapNum == HeapSize )
269 ResizeHeap( FMath::Max<uint32>( 32u, HeapSize * 2 ) );
272 if(
Index >= IndexSize )
274 ResizeIndexes(FMath::Max<uint32>(32u, FMath::RoundUpToPowerOfTwo(
Index + 1)));
279 IndexType HeapIndex = HeapNum++;
283 HeapIndexes[
Index ] = HeapIndex;
288template<
typename KeyType,
typename IndexType >
296 IndexType HeapIndex = HeapIndexes[
Index ];
297 IndexType
Parent = (HeapIndex - 1) >> 1;
298 if( HeapIndex > 0 && Key < Keys[
Heap[
Parent ] ] )
304 DownHeap( HeapIndex );
308template<
typename KeyType,
typename IndexType >
311 if( !IsPresent(
Index ) )
316 KeyType Key = Keys[
Index ];
317 IndexType HeapIndex = HeapIndexes[
Index ];
319 Heap[ HeapIndex ] =
Heap[ --HeapNum ];
320 HeapIndexes[
Heap[ HeapIndex ] ] = HeapIndex;
321 HeapIndexes[
Index ] = (IndexType)-1;
323 if( Key < Keys[
Heap[ HeapIndex ] ] )
325 DownHeap( HeapIndex );
333template<
typename KeyType,
typename IndexType >
336 IndexType Moving =
Heap[ HeapIndex ];
337 IndexType i = HeapIndex;
338 IndexType
Parent = (i - 1) >> 1;
340 while( i > 0 && Keys[ Moving ] < Keys[
Heap[
Parent ] ] )
343 HeapIndexes[
Heap[i] ] = i;
352 HeapIndexes[
Heap[i] ] = i;
356template<
typename KeyType,
typename IndexType >
359 IndexType Moving =
Heap[ HeapIndex ];
360 IndexType i = HeapIndex;
361 IndexType
Left = (i << 1) + 1;
364 while(
Left < HeapNum )
367 if(
Right < HeapNum )
375 HeapIndexes[
Heap[i] ] = i;
390 HeapIndexes[
Heap[i] ] = i;
394template<
typename KeyType,
typename IndexType >
402 HeapIndexes =
nullptr;
405#if UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_4
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define check(expr)
Definition AssertionMacros.h:314
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition BinaryHeap.h:20
FBinaryHeap(const FBinaryHeap &)=delete
uint32 GetIndexSize() const
Definition BinaryHeap.h:39
void Resize(uint32 NewHeapSize, uint32 NewIndexSize)
Definition BinaryHeap.h:204
FBinaryHeap()
Definition BinaryHeap.h:75
bool IsEmpty() const
Definition BinaryHeap.h:36
void operator=(const FBinaryHeap &)=delete
FBinaryHeap(FBinaryHeap &&Other)
Definition BinaryHeap.h:94
IndexType * Heap
Definition BinaryHeap.h:68
bool IsPresent(IndexType Index) const
Definition BinaryHeap.h:218
KeyType GetKey(IndexType Index) const
Definition BinaryHeap.h:228
void ResizeHeap(uint32 NewHeapSize)
Definition BinaryHeap.h:131
KeyType * Keys
Definition BinaryHeap.h:70
IndexType Peek(IndexType Index) const
Definition BinaryHeap.h:235
void DownHeap(IndexType HeapIndex)
Definition BinaryHeap.h:357
FBinaryHeap(uint32 InHeapSize, uint32 InIndexSize)
Definition BinaryHeap.h:81
void UpHeap(IndexType HeapIndex)
Definition BinaryHeap.h:334
void Update(KeyType Key, IndexType Index)
Definition BinaryHeap.h:289
uint32 IndexSize
Definition BinaryHeap.h:66
void ResetInternal()
Definition BinaryHeap.h:395
void Add(KeyType Key, IndexType Index)
Definition BinaryHeap.h:265
IndexType Top() const
Definition BinaryHeap.h:242
void ResizeIndexes(uint32 NewIndexSize)
Definition BinaryHeap.h:160
void Free()
Definition BinaryHeap.h:121
uint32 Num() const
Definition BinaryHeap.h:37
void Remove(IndexType Index)
Definition BinaryHeap.h:309
IndexType * HeapIndexes
Definition BinaryHeap.h:71
uint32 HeapSize
Definition BinaryHeap.h:65
~FBinaryHeap()
Definition BinaryHeap.h:108
void Pop()
Definition BinaryHeap.h:250
uint32 GetHeapSize() const
Definition BinaryHeap.h:38
uint32 HeapNum
Definition BinaryHeap.h:64
void Clear()
Definition BinaryHeap.h:114
U16 Index
Definition radfft.cpp:71
static UE_FORCEINLINE_HINT void * Memcpy(void *Dest, const void *Src, SIZE_T Count)
Definition UnrealMemory.h:160
static UE_FORCEINLINE_HINT void * Memset(void *Dest, uint8 Char, SIZE_T Count)
Definition UnrealMemory.h:119