当前位置:网站首页>U++ iterative Sorting Query learning notes

U++ iterative Sorting Query learning notes

2022-06-22 14:53:00 It's a bald rabbit

iteration

AUTO:

FString JoinedStr;
for (auto& Str : StrArr)
{
    JoinedStr += Str;
    JoinedStr += TEXT(" ");
}
// JoinedStr == "Hello Brave World of Tomorrow ! "

Index:

for (int32 Index = 0; Index != StrArr.Num(); ++Index)
{
    JoinedStr += StrArr[Index];
    JoinedStr += TEXT(" ");
}

Iterator:

for (auto It = StrArr.CreateConstIterator(); It; ++It)
{
    JoinedStr += *It;
    JoinedStr += TEXT(" ");
}

Sort

Sort:

StrArr.Sort();
// StrArr == ["!","Brave","Hello","of","Tomorrow","World"]

Lambda Declare collation ( Unstable ordering ,Sort For a quick row + Stack row + Insert ( According to the sorting depth of quick row disassembly, select whether to use quick row or heap row or insert row , I won't go into details here , You can go to see if you are interested sort Source code implementation )):

StrArr.Sort([](const FString& A, const FString& B) {
    return A.Len() < B.Len();
});
// StrArr == ["!","of","Hello","Brave","World","Tomorrow"]

  Heap sort use Lambda Declare collation ( Stable sequencing ):

StrArr.HeapSort([](const FString& A, const FString& B) {
    return A.Len() < B.Len();
});
// StrArr == ["!","of","Hello","Brave","World","Tomorrow"]

Stable sequencing (StableSort) Use Lambda Declare collation :

StrArr.StableSort([](const FString& A, const FString& B) {
    return A.Len() < B.Len();
});
// StrArr == ["!","of","Brave","Hello","World","Tomorrow"]

Inquire about

Num():

int32 Count = StrArr.Num();
// Count == 6

GetData(): The personal guess is that the operator is overloaded and then for Loop assignment

FString* StrPtr = StrArr.GetData();
// StrPtr[0] == "!"
// StrPtr[1] == "of"
// ...
// StrPtr[5] == "Tomorrow"
// StrPtr[6] - undefined behavior

 GetTypeSize(): The number of access elements byte

uint32 ElementSize = StrArr.GetTypeSize();
// ElementSize == sizeof(FString)

  Operator overloading operator[]: Can get FString * Subscript content of type

FString Elem1 = StrArr[1];
// Elem1 == "of"

isValidIndex(int): Pass invalid index ( Less than 0 Or greater than or equal to Num()) Will cause runtime errors .

bool bValidM1 = StrArr.IsValidIndex(-1);
bool bValid0  = StrArr.IsValidIndex(0);
bool bValid5  = StrArr.IsValidIndex(5);
bool bValid6  = StrArr.IsValidIndex(6);
// bValidM1 == false
// bValid0  == true
// bValid5  == true
// bValid6  == false

ToUpper():

StrArr[3] = StrArr[3].ToUpper();
// StrArr == ["!","of","Brave","HELLO","World","Tomorrow"]

Last() & Top() & Last(int) & Top(int): These two functions are the same , It starts with the last bit of the array

FString ElemEnd  = StrArr.Last();
FString ElemEnd0 = StrArr.Last(0);
FString ElemEnd1 = StrArr.Last(1);
FString ElemTop  = StrArr.Top();
// ElemEnd  == "Tomorrow"
// ElemEnd0 == "Tomorrow"
// ElemEnd1 == "World"
// ElemTop  == "Tomorrow"

Contain(value): Whether the array contains value value

bool bHello   = StrArr.Contains(TEXT("Hello"));
bool bGoodbye = StrArr.Contains(TEXT("Goodbye"));
// bHello   == true
// bGoodbye == false

 Find(value): We can use Find Function family find element . To check if an element exists and return its index .

int32 Index;
if (StrArr.Find(TEXT("Hello"), Index))
{
    // Index == 3
}

FindLast(value): If there are repeating elements , And we want to find the index of the last element .

int32 IndexLast;
if (StrArr.FindLast(TEXT("Hello"), IndexLast))
{
    // IndexLast == 3, because there aren't any duplicates
}

 Find And FIndLast If the specified value is not found, a special return value will be returned (INDEX_NONE):

 

int32 Index2     = StrArr.Find(TEXT("Hello"));
int32 IndexLast2 = StrArr.FindLast(TEXT("Hello"));
int32 IndexNone  = StrArr.Find(TEXT("None"));
// Index2     == 3
// IndexLast2 == 3
// IndexNone  == INDEX_NONE

 IndexOfByKey(value):IndexOfByKey Apply to operator==(ElementType, KeyType) Any key type that exists .IndexOfByKey Will return the index of the first found element , perhaps INDEX_NONE If the element is not found :

int32 Index = StrArr.IndexOfByKey(TEXT("Hello"));
// Index == 3

 

原网站

版权声明
本文为[It's a bald rabbit]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221321591109.html