Making WordList array valid: using reference to original - Different approach

Hello ,

Just wondering if that’s better according to performance?
I made function which is changing original array to new isogram only array.
That functon(IsogramArrayProvider) is called at the beginning of the game:

The definition of this function is here:

However if words list is very long compiling time is pretty long as well.
So I’m not sure what’s better according to performance? Any ideas?

There is no length checking instructions because I’ve already done code sensitive
for word length so you can provide any length words.I also attached link to all code:

https://drive.google.com/open?id=17i2RcaLV8ORajl6It1lejypKgUY1VpMR

Cheers

I think you’ll find that you have a bug. Try your function with this set of words

TArray<FString> TestWords =
{
	TEXT("ability"),
	TEXT("accept"),
	TEXT("according"),
	TEXT("account"),
	TEXT("across"),
	TEXT("act"),
	TEXT("action"),
	TEXT("activity"),
	TEXT("actually")
};
1 Like

Thanks a lot Dan,

I tried to fix that bug after work yesterday but couldn’t find any proper solution.
I fix that bug this way but it was not what I want.I didn’t want to create another array just for learning purposes and simplicity.That’s what I created yesterday:


It works but I don’t like it, too complicated and another array created

But today I found much easier option similar to the first one:

Thanks again for your reply.
Luke

That’s what I was hinting at. Mike was going to go that route but I said it’s error prone and I expected quite a few people to implement it incorrectly and get into out of bounds troubles.

Alternatively you could have done

for (int32 Index = 0; Index < WordList.Num(); /*purposely empty*/)
{
    if (!IsIsogram(WordList[Index])
    {
        WordList.RemoveAt(Index);
    }
    else
    {
        ++Index;
    }
}

If you wanted to load from a file instead you could use FFilePath and FFileHelper

//FString::operator/ concatenates strings ensuring there's a '/' between them.
const FString Path = FPaths::ProjectContentDir() / TEXT("Word Lists/Basic.txt");
TArray<FString> Result;
FFileHelper::LoadFileToStringArray(Result, *Path);

//Remove non-isograms and ToLower strings in Result
//code..

Cheers for that. Incrementing only when word is isogram seems to be even more clear to me.

Forgot to answer the performance question. It should be better, but what’s better is never having them be correct in the first place so you don’t do anything.

In terms of performance sorted by better performing I would assume the following

  1. Precomputed valid word list
  2. Only add what you want when creating the array e.g. I made a pull request for Unreal for a LoadFileToStringArrayWithPredicate function so instead of adding every line in a file to an array, only add lines that match a predicate.
  3. Add everything and then remove the unwanted words
  4. Create a new array out of a given array (what’s done in the course).

I’m not entirely sure about the last two being in the correct order but I feel like it’s correct. Would have to benchmark to be certain.

Thanks Daniel