Description
Removes an arbitrary element at the given index from the heap, then restores heap order by sifting the replacement element both up and down as needed.
Caveats & Gotchas
- • Index must be a heap index (into the array's contiguous storage), not a logical priority rank. After any heap mutation the positions of elements change, so cached indices go stale immediately.
- • The implementation does a RemoveAtSwap followed by both HeapSiftDown and HeapSiftUp, making it O(log n) but with a larger constant than HeapPop. Avoid in hot paths if possible.
- • There is no version that returns the removed element — copy it out via operator[] before calling HeapRemoveAt if you need the value.
Signature
void HeapRemoveAt(SizeType Index, EAllowShrinking AllowShrinking = UE::Core::Private::AllowShrinkingByDefault<AllocatorType>()) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Index | SizeType | Heap index of the element to remove. | — |
| AllowShrinking | EAllowShrinking | Controls whether the array may shrink its allocation after removal. | UE::Core::Private::AllowShrinkingByDefault<AllocatorType>() |
Return Type
void Example
Cancelling a specific pending task from a priority queue C++
TArray<FTask> TaskHeap;
// ... heap is populated ...
// Find the task we want to cancel (e.g. by task ID)
int32 CancelIdx = TaskHeap.IndexOfByPredicate([&](const FTask& T){ return T.Id == CancelId; });
if (CancelIdx != INDEX_NONE)
{
FTask Removed = TaskHeap[CancelIdx]; // save before removing
TaskHeap.HeapRemoveAt(CancelIdx, EAllowShrinking::No);
} Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?