UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Map.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6
7namespace uLang
8{
9 class CHeapRawAllocator;
10
11template<class KeyType, class ValueType, class HashTraits, class AllocatorType, typename... AllocatorArgsType>
12class TMapG
13{
15
16public:
18
20 ULANG_FORCEINLINE bool Contains(const KeyType& Key) const { return _HashTable.Contains(Key); }
21 ULANG_FORCEINLINE ValueType* Find(const KeyType& Key) { PairType* Pair = _HashTable.Find(Key); return Pair ? &Pair->_Value : nullptr; }
22 ULANG_FORCEINLINE const ValueType* Find(const KeyType& Key) const { const PairType* Pair = _HashTable.Find(Key); return Pair ? &Pair->_Value : nullptr; }
23
24 template <typename Predicate>
26 {
28 }
29
30 template <typename Predicate>
35
36 ULANG_FORCEINLINE PairType& Insert(const KeyType& Key, ValueType&& Value) { return _HashTable.Insert({ Key, Move(Value) }); }
37 ULANG_FORCEINLINE PairType& Insert(KeyType&& Key, const ValueType& Value) { return _HashTable.Insert({ Move(Key), Value }); }
38 ULANG_FORCEINLINE PairType& Insert(const KeyType& Key, const ValueType& Value) { return _HashTable.Insert({ Key, ValueType(Value) }); }
39 ULANG_FORCEINLINE PairType& Insert(KeyType&& Key, ValueType&& Value) { return _HashTable.Insert({ Move(Key), Move(Value) }); }
40
41 template <typename OtherKeyType, typename OtherValueType>
46
47 template <typename OtherKeyType>
52
53 ULANG_FORCEINLINE bool Remove(const KeyType& Key) { return _HashTable.Remove(Key); }
55
56 ULANG_FORCEINLINE ValueType& operator[](const KeyType& Key)
57 {
58 PairType* Pair = _HashTable.Find(Key);
59 if (Pair)
60 {
61 return Pair->_Value;
62 }
63 else
64 {
65 ValueType DefaultValue{};
66 KeyType NewKey(Key);
67 Insert(Move(NewKey), Move(DefaultValue));
68 return _HashTable.Find(Key)->_Value;
69 }
70 }
71
72 using HashTableType = THashTable<KeyType, PairType, HashTraits, AllocatorType, AllocatorArgsType...>;
73 using ConstIterator = typename HashTableType::template Iterator<true>;
74 using Iterator = typename HashTableType::template Iterator<false>;
75
80
82 {
83 return _HashTable.end();
84 }
85
87 {
88 return _HashTable.cbegin();
89 }
90
92 {
93 return _HashTable.cend();
94 }
95
97 {
98 return _HashTable.cbegin();
99 }
100
102 {
103 return _HashTable.cend();
104 }
105
106protected:
108};
109
110// A map that assumes that the KeyType has a method `GetTypeHash`(), and that allocates memory from the heap
111template<class KeyType, class ValueType>
113
114} // namespace uLang
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define ULANG_FORCEINLINE
Definition Common.h:188
Raw memory allocator that allocates memory from the global heap.
Definition Allocator.h:64
ULANG_FORCEINLINE uint32_t Num() const
Definition HashTable.h:68
ULANG_FORCEINLINE Iterator< true > cend() const
Definition HashTable.h:374
KeyValueType & Insert(const KeyValueType &KeyValue)
Definition HashTable.h:134
ULANG_FORCEINLINE Iterator< true > cbegin() const
Definition HashTable.h:365
KeyValueType & FindOrInsert(KeyValueType &&KeyValue)
Definition HashTable.h:144
ULANG_FORCEINLINE bool Contains(const KeyType &Key) const
Definition HashTable.h:73
void Empty()
Definition HashTable.h:231
ULANG_FORCEINLINE Iterator< false > end()
Definition HashTable.h:350
ULANG_FORCEINLINE Iterator< false > begin()
Definition HashTable.h:341
ULANG_FORCEINLINE KeyValueType * Find(const KeyType &Key)
Definition HashTable.h:78
bool Remove(const KeyType &Key)
Definition HashTable.h:156
const KeyValueType * FindByPredicate(Predicate Pred) const
Definition HashTable.h:99
Definition Map.h:13
ULANG_FORCEINLINE bool Contains(const KeyType &Key) const
Definition Map.h:20
ULANG_FORCEINLINE PairType & Insert(const KeyType &Key, const ValueType &Value)
Definition Map.h:38
ULANG_FORCEINLINE void Empty()
Definition Map.h:54
ULANG_FORCEINLINE PairType & FindOrInsert(OtherKeyType &&Key, OtherValueType &&Value)
Definition Map.h:42
ULANG_FORCEINLINE ConstIterator cbegin() const
Definition Map.h:96
ULANG_FORCEINLINE PairType & Insert(KeyType &&Key, ValueType &&Value)
Definition Map.h:39
ULANG_FORCEINLINE Iterator begin()
Definition Map.h:76
ULANG_FORCEINLINE PairType * FindByPredicate(Predicate Pred)
Definition Map.h:31
HashTableType _HashTable
Definition Map.h:107
ULANG_FORCEINLINE PairType & FindOrInsert(OtherKeyType &&Key)
Definition Map.h:48
typename HashTableType::template Iterator< false > Iterator
Definition Map.h:74
ULANG_FORCEINLINE PairType & Insert(const KeyType &Key, ValueType &&Value)
Definition Map.h:36
TMapG(AllocatorArgsType &&... AllocatorArgs)
Definition Map.h:17
ULANG_FORCEINLINE ConstIterator end() const
Definition Map.h:91
ULANG_FORCEINLINE PairType & Insert(KeyType &&Key, const ValueType &Value)
Definition Map.h:37
ULANG_FORCEINLINE ValueType * Find(const KeyType &Key)
Definition Map.h:21
ULANG_FORCEINLINE uint32_t Num() const
Definition Map.h:19
ULANG_FORCEINLINE bool Remove(const KeyType &Key)
Definition Map.h:53
typename HashTableType::template Iterator< true > ConstIterator
Definition Map.h:73
ULANG_FORCEINLINE const ValueType * Find(const KeyType &Key) const
Definition Map.h:22
ULANG_FORCEINLINE const PairType * FindByPredicate(Predicate Pred) const
Definition Map.h:25
ULANG_FORCEINLINE Iterator end()
Definition Map.h:81
ULANG_FORCEINLINE ConstIterator cend() const
Definition Map.h:101
ULANG_FORCEINLINE ConstIterator begin() const
Definition Map.h:86
ULANG_FORCEINLINE ValueType & operator[](const KeyType &Key)
Definition Map.h:56
Definition VVMEngineEnvironment.h:23
ULANG_FORCEINLINE T && ForwardArg(typename TRemoveReference< T >::Type &Obj)
Definition References.h:115
ULANG_FORCEINLINE TRemoveReference< T >::Type && Move(T &&Obj)
Definition References.h:86
Definition HashTable.h:18
ValueType _Value
Definition HashTable.h:20