데이터 값 자체를 키로 사용하는 컨테이너. 엘리먼트 추가, 검색, 제거가 매우 빠름.
TSet<FString> FruitSet;
FruitSet.Add(TEXT("Banana"));
FruitSet.Add(TEXT("Grapefruit"));
FruitSet.Add(TEXT("Pineapple"));
// FruitSet == [ "Banana", "Grapefruit", "Pineapple" ]
FruitSet.Add(TEXT("Pear"));
FruitSet.Add(TEXT("Banana")); // 중복 허용 안함.
// FruitSet == [ "Banana", "Grapefruit", "Pineapple", "Pear" ]
FruitSet.Emplace(TEXT("Orange"));
// FruitSet == [ "Banana", "Grapefruit", "Pineapple", "Pear", "Orange" ]
TSet<FString> FruitSet2;
FruitSet2.Emplace(TEXT("Kiwi"));
FruitSet2.Emplace(TEXT("Melon"));
FruitSet2.Emplace(TEXT("Mango"));
FruitSet2.Emplace(TEXT("Orange"));
FruitSet.Append(FruitSet2);
// FruitSet == [ "Banana", "Grapefruit", "Pineapple", "Pear", "Orange", "Kiwi", "Melon", "Mango" ]
for (auto& Elem : FruitSet)
{
FPlatformMisc::LocalPrint(
*FString::Printf(
TEXT(" \"%s\"\n"),
*Elem
)
);
}
for (auto It = FruitSet.CreateConstIterator(); It; ++It)
{
FPlatformMisc::LocalPrint(
*FString::Printf(
TEXT("(%s)\n"),
*It
)
);
}
// Output:
// "Banana"
// "Grapefruit"
// "Pineapple"
// "Pear"
// "Orange"
// "Kiwi"
// "Melon"
// "Mango"
int32 Count = FruitSet.Num(); // Count == 8
bool bHasBanana = FruitSet.Contains(TEXT("Banana")); // bHasBanana == true
bool bHasLemon = FruitSet.Contains(TEXT("Lemon")); // bHasLemon == false
FSetElementId BananaIndex = FruitSet.Index(TEXT("Banana"));
// BananaIndex is a value between 0 and (FruitSet.Num() - 1)
FPlatformMisc::LocalPrint(
*FString::Printf(
TEXT(" \"%s\"\n"),
*FruitSet[BananaIndex]
)
); // Prints "Banana"
FString* PtrBanana = FruitSet.Find(TEXT("Banana")); // *PtrBanana == "Banana"
FString* PtrLemon = FruitSet.Find(TEXT("Lemon")); // PtrLemon == nullptr
FruitSet.Remove(0); // FruitSet == [ "Grapefruit","Pineapple","Pear","Orange","Kiwi","Melon","Mango" ]
int32 RemovedAmountPineapple = FruitSet.Remove(TEXT("Pineapple")); // RemovedAmountPineapple == 1
// FruitSet == [ "Grapefruit","Pear","Orange","Kiwi","Melon","Mango" ]
FString RemovedAmountLemon = FruitSet.Remove(TEXT("Lemon")); // RemovedAmountLemon == 0
TSet<FString> FruitSetCopy = FruitSet; // FruitSetCopy == [ "Grapefruit","Pear","Orange","Kiwi","Melon","Mango" ]
FruitSetCopy.Empty(); // FruitSetCopy == []
// 소팅.
FruitSet.Sort([](const FString& A, const FString& B) {
return A.Len() < B.Len(); // 단어의 길이가 짧은 것부터.
});
// FruitSet == [ "Pear", "Kiwi", "Melon", "Mango", "Orange", "Grapefruit" ]
'::protected > 언리얼4&5' 카테고리의 다른 글
TSubclassOf (0) | 2019.11.12 |
---|---|
오브젝트(Object) 생성 (0) | 2019.11.12 |
TMap (0) | 2019.10.17 |
TArray (0) | 2019.10.17 |
스트링 처리 (0) | 2019.10.17 |