UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TSortedMap< InKeyType, InValueType, ArrayAllocator, SortPredicate > Class Template Reference

#include <SortedMap.h>

+ Inheritance diagram for TSortedMap< InKeyType, InValueType, ArrayAllocator, SortPredicate >:

Classes

class  TConstIterator
 
class  TConstKeyIterator
 
class  TConstReverseIterator
 
class  TIterator
 
class  TKeyIterator
 
class  TReverseIterator
 

Public Types

typedef InKeyType KeyType
 
typedef InValueType ValueType
 
typedef TTypeTraits< KeyType >::ConstPointerType KeyConstPointerType
 
typedef TTypeTraits< KeyType >::ConstInitType KeyInitType
 
typedef TTypeTraits< ValueType >::ConstInitType ValueInitType
 
typedef TPair< KeyType, ValueTypeElementType
 
using IntrusiveUnsetOptionalStateType = TSortedMap
 
typedef ElementArrayType::RangedForIteratorType RangedForIteratorType
 
typedef ElementArrayType::RangedForConstIteratorType RangedForConstIteratorType
 

Public Member Functions

 TSortedMap ()=default
 
 TSortedMap (TSortedMap &&)=default
 
 TSortedMap (const TSortedMap &)=default
 
TSortedMapoperator= (TSortedMap &&)=default
 
TSortedMapoperator= (const TSortedMap &)=default
 
template<typename OtherArrayAllocator >
 TSortedMap (TSortedMap< KeyType, ValueType, OtherArrayAllocator, SortPredicate > &&Other)
 
template<typename OtherArrayAllocator >
 TSortedMap (const TSortedMap< KeyType, ValueType, OtherArrayAllocator, SortPredicate > &Other)
 
 TSortedMap (std::initializer_list< TPairInitializer< const KeyType &, const ValueType & > > InitList)
 
 TSortedMap (FIntrusiveUnsetOptionalState Tag)
 
bool operator== (FIntrusiveUnsetOptionalState Tag) const
 
template<typename OtherArrayAllocator >
TSortedMapoperator= (TSortedMap< KeyType, ValueType, OtherArrayAllocator, SortPredicate > &&Other)
 
template<typename OtherArrayAllocator >
TSortedMapoperator= (const TSortedMap< KeyType, ValueType, OtherArrayAllocator, SortPredicate > &Other)
 
TSortedMapoperator= (std::initializer_list< TPairInitializer< const KeyType &, const ValueType & > > InitList)
 
UE_FORCEINLINE_HINT bool operator== (const TSortedMap &Other) const
 
UE_FORCEINLINE_HINT bool operator!= (const TSortedMap &Other) const
 
UE_FORCEINLINE_HINT void Empty (int32 ExpectedNumElements=0)
 
UE_FORCEINLINE_HINT void Reset ()
 
UE_FORCEINLINE_HINT void Shrink ()
 
UE_FORCEINLINE_HINT void Reserve (int32 Number)
 
bool IsEmpty () const
 
UE_FORCEINLINE_HINT int32 Num () const
 
UE_FORCEINLINE_HINT int32 Max () const
 
UE_FORCEINLINE_HINT SIZE_T GetAllocatedSize () const
 
UE_FORCEINLINE_HINT void CountBytes (FArchive &Ar) const
 
UE_FORCEINLINE_HINT ValueTypeAdd (const KeyType &InKey, const ValueType &InValue)
 
UE_FORCEINLINE_HINT ValueTypeAdd (const KeyType &InKey, ValueType &&InValue)
 
UE_FORCEINLINE_HINT ValueTypeAdd (KeyType &&InKey, const ValueType &InValue)
 
UE_FORCEINLINE_HINT ValueTypeAdd (KeyType &&InKey, ValueType &&InValue)
 
UE_FORCEINLINE_HINT ValueTypeAdd (const KeyType &InKey)
 
UE_FORCEINLINE_HINT ValueTypeAdd (KeyType &&InKey)
 
template<typename InitKeyType = KeyType, typename InitValueType = ValueType>
ValueTypeEmplace (InitKeyType &&InKey, InitValueType &&InValue)
 
template<typename InitKeyType = KeyType>
ValueTypeEmplace (InitKeyType &&InKey)
 
int32 Remove (KeyConstPointerType InKey)
 
const KeyTypeFindKey (ValueInitType Value) const
 
ValueTypeFind (KeyConstPointerType Key)
 
UE_FORCEINLINE_HINT const ValueTypeFind (KeyConstPointerType Key) const
 
UE_FORCEINLINE_HINT ValueTypeFindOrAdd (const KeyType &Key)
 
UE_FORCEINLINE_HINT ValueTypeFindOrAdd (KeyType &&Key)
 
ValueTypeFindChecked (KeyConstPointerType Key)
 
const ValueTypeFindChecked (KeyConstPointerType Key) const
 
ValueType FindRef (KeyConstPointerType Key) const
 
ValueType FindRef (KeyConstPointerType Key, ValueType DefaultValue) const
 
ElementTypeFindArbitraryElement ()
 
const ElementTypeFindArbitraryElement () const
 
bool Contains (KeyConstPointerType Key) const
 
template<typename Allocator >
int32 GetKeys (TArray< KeyType, Allocator > &OutKeys) const
 
template<typename Allocator >
void GenerateKeyArray (TArray< KeyType, Allocator > &OutArray) const
 
template<typename Allocator >
void GenerateValueArray (TArray< ValueType, Allocator > &OutArray) const
 
void Dump (FOutputDevice &Ar)
 
bool RemoveAndCopyValue (KeyInitType Key, ValueType &OutRemovedValue)
 
ValueType FindAndRemoveChecked (KeyConstPointerType Key)
 
template<typename OtherArrayAllocator , typename OtherSortPredicate >
void Append (TSortedMap< KeyType, ValueType, OtherArrayAllocator, OtherSortPredicate > &&OtherMap)
 
template<typename OtherArrayAllocator , typename OtherSortPredicate >
void Append (const TSortedMap< KeyType, ValueType, OtherArrayAllocator, OtherSortPredicate > &OtherMap)
 
UE_FORCEINLINE_HINT ValueTypeoperator[] (KeyConstPointerType Key)
 
UE_FORCEINLINE_HINT const ValueTypeoperator[] (KeyConstPointerType Key) const
 
 UE_DEPRECATED (5.7 until 5.9, "GetMaxIndex() should be replaced with Num() - 1.") UE_FORCEINLINE_HINT int32 GetMaxIndex() const
 
UE_FORCEINLINE_HINT bool IsValidId (FSetElementId Id) const
 
UE_FORCEINLINE_HINT ElementTypeGet (FSetElementId Id)
 
UE_FORCEINLINE_HINT const ElementTypeGet (FSetElementId Id) const
 
UE_FORCEINLINE_HINT TIterator CreateIterator ()
 
UE_FORCEINLINE_HINT TConstIterator CreateConstIterator () const
 
UE_FORCEINLINE_HINT TKeyIterator CreateKeyIterator (KeyInitType InKey)
 
UE_FORCEINLINE_HINT TConstKeyIterator CreateConstKeyIterator (KeyInitType InKey) const
 
UE_FORCEINLINE_HINT RangedForIteratorType begin ()
 
UE_FORCEINLINE_HINT RangedForConstIteratorType begin () const
 
UE_FORCEINLINE_HINT RangedForIteratorType end ()
 
UE_FORCEINLINE_HINT RangedForConstIteratorType end () const
 

Static Public Attributes

static constexpr bool bHasIntrusiveUnsetOptionalState = true
 

Friends

template<typename OtherKeyType , typename OtherValueType , typename OtherArrayAllocator , typename OtherSortPredicate >
class TSortedMap
 
struct TSortedMapPrivateFriend
 

Detailed Description

template<typename InKeyType, typename InValueType, typename ArrayAllocator, typename SortPredicate>
class TSortedMap< InKeyType, InValueType, ArrayAllocator, SortPredicate >

A Map of keys to value, implemented as a sorted TArray of TPairs.

It has a mostly identical interface to TMap and is designed as a drop in replacement. Keys must be unique, there is no equivalent sorted version of TMultiMap. It uses half as much memory as TMap, but adding and removing elements is O(n), and finding is O(Log n). In practice it is faster than TMap for low element counts, and slower as n increases, This map is always kept sorted by the key type so cannot be sorted manually.

Member Typedef Documentation

◆ ElementType

◆ IntrusiveUnsetOptionalStateType

◆ KeyConstPointerType

◆ KeyInitType

◆ KeyType

◆ RangedForConstIteratorType

◆ RangedForIteratorType

Ranged For iterators. Unlike normal TMap these are not the same as the normal iterator for performance reasons

◆ ValueInitType

◆ ValueType

Constructor & Destructor Documentation

◆ TSortedMap() [1/7]

◆ TSortedMap() [2/7]

◆ TSortedMap() [3/7]

◆ TSortedMap() [4/7]

◆ TSortedMap() [5/7]

◆ TSortedMap() [6/7]

Constructor which gets its elements from a native initializer list

◆ TSortedMap() [7/7]

Member Function Documentation

◆ Add() [1/6]

Sets a default value associated with a key.

Parameters
InKeyThe key to associate the value with.
Returns
A reference to the value as stored in the map. The reference is only valid until the next change to any key in the map.

◆ Add() [2/6]

Sets the value associated with a key.

Parameters
InKeyThe key to associate the value with.
InValueThe value to associate with the key.
Returns
A reference to the value as stored in the map (only valid until the next change to any key in the map).

◆ Add() [3/6]

◆ Add() [4/6]

◆ Add() [5/6]

◆ Add() [6/6]

◆ Append() [1/2]

Add all items from another map to our map (if any keys are in both, the value from the other map wins).

Parameters
OtherMapThe other map of items to add.

◆ Append() [2/2]

Move all items from another map into our map (if any keys are in both, the value from the other map wins) and empty the other map.

Parameters
OtherMapThe other map of items to move the elements from.

◆ begin() [1/2]

DO NOT USE DIRECTLY STL-like iterators to enable range-based for loop support.

◆ begin() [2/2]

◆ Contains()

Checks if map contains the specified key.

Parameters
KeyThe key to check for.
Returns
true if the map contains the key.

◆ CountBytes()

Tracks the container's memory use through an archive.

◆ CreateConstIterator()

Creates a const iterator over all the pairs in this map

◆ CreateConstKeyIterator()

Creates a const iterator over the values associated with a specified key in a map. This will be at most one value because keys must be unique

◆ CreateIterator()

Creates an iterator over all the pairs in this map

◆ CreateKeyIterator()

Creates an iterator over the values associated with a specified key in a map. This will be at most one value because keys must be unique

◆ Dump()

Describes the map's contents through an output device.

Parameters
ArThe output device to describe the map's contents through.

◆ Emplace() [1/2]

Sets a default value associated with a key.

Parameters
InKeyThe key to associate the value with.
Returns
A reference to the value as stored in the map (only valid until the next change to any key in the map).

◆ Emplace() [2/2]

Sets the value associated with a key.

Parameters
InKey- The key to associate the value with.
InValue- The value to associate with the key.
Returns
A reference to the value as stored in the map (only valid until the next change to any key in the map).

◆ Empty()

Removes all elements from the map, potentially leaving space allocated for an expected number of elements about to be added.

Parameters
ExpectedNumElementsThe number of elements about to be added to the set.

◆ end() [1/2]

◆ end() [2/2]

◆ Find() [1/2]

Returns the value associated with a specified key.

Parameters
KeyThe key to search for.
Returns
A pointer to the value associated with the specified key, or nullptr if the key isn't contained in this map. The pointer (only valid until the next change to any key in the map).

◆ Find() [2/2]

◆ FindAndRemoveChecked()

Finds a pair with the specified key, removes it from the map, and returns the value part of the pair. If no pair was found, an exception is thrown.

Parameters
KeyThe key to search for
Returns
Whether or not the key was found

◆ FindArbitraryElement() [1/2]

Finds any pair in the map and returns a pointer to it. Callers should not depend on particular patterns in the behaviour of this function.

Returns
A pointer to an arbitrary pair, or nullptr if the container is empty.

◆ FindArbitraryElement() [2/2]

◆ FindChecked() [1/2]

Returns a reference to the value associated with a specified key.

Parameters
KeyThe key to search for.
Returns
The value associated with the specified key, or triggers an assertion if the key does not exist.

◆ FindChecked() [2/2]

◆ FindKey()

Returns the key associated with the specified value. The time taken is O(N) in the number of pairs.

Parameters
ValueThe value to search for.
Returns
A pointer to the key associated with the specified value, or nullptr if the value isn't contained in this map (only valid until the next change to any key in the map).

◆ FindOrAdd() [1/2]

Returns the value associated with a specified key, or if none exists, adds a value using the default constructor.

Parameters
KeyThe key to search for.
Returns
A reference to the value associated with the specified key.

◆ FindOrAdd() [2/2]

◆ FindRef() [1/2]

Returns the value associated with a specified key.

Parameters
KeyThe key to search for.
Returns
The value associated with the specified key, or the default value for the ValueType if the key isn't contained in this map.

◆ FindRef() [2/2]

Returns the value associated with a specified key.

Parameters
KeyThe key to search for.
DefaultValueThe fallback value if the key is not found.
Returns
The value associated with the specified key, or DefaultValue if the key isn't contained in this map.

◆ GenerateKeyArray()

Generates an array from the keys in this map.

◆ GenerateValueArray()

Generates an array from the values in this map.

◆ Get() [1/2]

Return a mapped pair by internal identifier. Element must be valid (see @IsValidId).

◆ Get() [2/2]

Return a mapped pair by internal identifier. Element must be valid (see @IsValidId).

◆ GetAllocatedSize()

Helper function to return the amount of memory allocated by this container. Only returns the size of allocations made directly by the container, not the elements themselves.

Returns
number of bytes allocated by this container.

◆ GetKeys()

Returns the unique keys contained within this map.

Parameters
OutKeysUpon return, contains the set of unique keys in this map.
Returns
The number of unique keys in the map.

◆ IsEmpty()

Returns true if the map is empty and contains no elements.

Returns
True if the map is empty.
See also
Num

◆ IsValidId()

Checks whether an element id is valid.

Parameters
Id- The element id to check.
Returns
true if the element identifier refers to a valid element in this map.

◆ Max()

Returns
The number of elements the map can hold before reallocation.

◆ Num()

◆ operator!=()

Inequality operator. This is efficient because pairs are always sorted.

◆ operator=() [1/5]

◆ operator=() [2/5]

Assignment operator for copying elements from a TSortedMap with a different ArrayAllocator.

◆ operator=() [3/5]

TSortedMap & TSortedMap< InKeyType, InValueType, ArrayAllocator, SortPredicate >::operator= ( std::initializer_list< TPairInitializer< const KeyType &, const ValueType & > >  InitList)
inline

Assignment operator which gets its elements from a native initializer list

◆ operator=() [4/5]

◆ operator=() [5/5]

Assignment operator for moving elements from a TSortedMap with a different ArrayAllocator.

◆ operator==() [1/2]

Equality operator. This is efficient because pairs are always sorted.

◆ operator==() [2/2]

◆ operator[]() [1/2]

◆ operator[]() [2/2]

◆ Remove()

Removes all value associations for a key.

Parameters
InKeyThe key to remove associated values for.
Returns
The number of values that were associated with the key.

◆ RemoveAndCopyValue()

Removes the pair with the specified key and copies the value that was removed to the ref parameter.

Parameters
KeyThe key to search for
OutRemovedValueIf found, the value that was removed (not modified if the key was not found)
Returns
Whether or not the key was found

◆ Reserve()

Preallocates enough memory to contain Number elements.

◆ Reset()

Efficiently empties out the map but preserves all allocations and capacities.

◆ Shrink()

◆ UE_DEPRECATED()

TSortedMap< InKeyType, InValueType, ArrayAllocator, SortPredicate >::UE_DEPRECATED ( 5.7 until 5.  9,
"GetMaxIndex() should be replaced with Num() - 1."   
) const
inline
Returns
The non-inclusive maximum index of elements in the map (was: the max valid index of the elements in the sparse storage).

Friends And Related Symbol Documentation

◆ TSortedMap

◆ TSortedMapPrivateFriend

Member Data Documentation

◆ bHasIntrusiveUnsetOptionalState


The documentation for this class was generated from the following file: