Is this iteration system correct?
Or is there a more efficient way to do the search?
/** @returns list of most important checkpoints of overlapped
*
* @param IgnoredCheckpoints Checkpoints to exclude from search
*/
TArray<ADHCheckpoint*> ADHPawn::GetImportantCheckpoints(TArray<ADHCheckpoint*> IgnoredCheckpoitns) const
{
TArray<ADHCheckpoint*> ReturnValue;
int32 CurrentRecord = -1;
int32 Counter, ArrayLength;
for (Counter = 0, ArrayLength = OverlappedCheckpoints.Num(); Counter <= ArrayLength; Counter += 1)
{
bool bSkipIteration = false;
int32 IgnoreCounter, IgnoreLength;
for (IgnoreCounter = 0, IgnoreLength = IgnoredCheckpoitns.Num(); IgnoreCounter <= IgnoreLength; IgnoreCounter += 1)
{
bSkipIteration = bSkipIteration || (OverlappedCheckpoints[Counter] == IgnoredCheckpoitns[IgnoreCounter]);
}
if (!bSkipIteration && (OverlappedCheckpoints[Counter]->CheckpointImportance >= CurrentRecord))
{
CurrentRecord = OverlappedCheckpoints[Counter]->CheckpointImportance;
ReturnValue.AddUnique(OverlappedCheckpoints[Counter]);
}
}
// Re-using iteration counters here is totally fine
for (Counter = 0, ArrayLength = ReturnValue.Num(); Counter <= ArrayLength; Counter += 1)
{
if (ReturnValue[Counter]->CheckpointImportance < CurrentRecord) ReturnValue.Remove(ReturnValue[Counter]);
}
return ReturnValue;
}