TSortedMap

A Map of keys to value, implemented as a sorted [TArray](API\Runtime\Core\Containers\TArray) of TPairs.

Windows
MacOS
Linux

Inheritance Hierarchy

TSortedMap

FAssetDataTagMap

References

Module

Core

Header

/Engine/Source/Runtime/Core/Public/Containers/SortedMap.h

Include

#include "Containers/SortedMap.h"

Syntax

template<typename KeyType, typename ValueType, typename ArrayAllocator, typename SortPredicate>
class TSortedMap

Remarks

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.

Constructors

Name Description

Public function

TSortedMap()

Public function

TSortedMap

(
    TSortedMap&&
)

Public function

TSortedMap

(
    const TSortedMap&
)

Public function

TSortedMap

(
    TSortedMap< KeyType, ValueType, Oth...
)

Constructor for moving elements from a TSortedMap with a different ArrayAllocator.

Public function

TSortedMap

(
    const TSortedMap< KeyType, ValueTyp...
)

Constructor for copying elements from a TSortedMap with a different ArrayAllocator.

Functions

Name Description

Public function

ValueType &

 

Add

(
    const KeyType& InKey,
    ValueType&& InValue
)

Public function

ValueType &

 

Add

(
    KeyType&& InKey,
    ValueType&& InValue
)

Public function

ValueType &

 

Add

(
    KeyType&& InKey,
    const ValueType& InValue
)

Public function

ValueType &

 

Add

(
    const KeyType& InKey,
    const ValueType& InValue
)

Sets the value associated with a key.

Public function

ValueType &

 

Add

(
    KeyType&& InKey
)

Public function

ValueType &

 

Add

(
    const KeyType& InKey
)

Sets a default value associated with a key.

Public function

void

 

Append

(
    const TSortedMap< KeyType, ValueTyp...
)

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

Public function

void

 

Append

(
    TSortedMap< KeyType, ValueType, Oth...
)

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.

Public function Const

RangedForCon...

 

begin()

Public function

RangedForIte...

 

begin()

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

Public function Const

bool

 

Contains

(
    KeyConstPointerType Key
)

Checks if map contains the specified key.

Public function Const

void

 

CountBytes

(
    FArchive& Ar
)

Tracks the container's memory use through an archive.

Public function Const

TConstIterat...

 

CreateConstIterator()

Creates a const iterator over all the pairs in this map

Public function Const

TConstKeyIte...

 

CreateConstKeyIterator

(
    KeyInitType InKey
)

Creates a const iterator over the values associated with a specified key in a map.

Public function

TIterator

 

CreateIterator()

Creates an iterator over all the pairs in this map

Public function

TKeyIterator

 

CreateKeyIterator

(
    KeyInitType InKey
)

Creates an iterator over the values associated with a specified key in a map.

Public function

void

 

Dump

(
    FOutputDevice& Ar
)

Describes the map's contents through an output device.

Public function

ValueType &

 

Emplace

(
    InitKeyType&& InKey,
    InitValueType&& InValue
)

Sets the value associated with a key.

Public function

ValueType &

 

Emplace

(
    InitKeyType&& InKey
)

Sets a default value associated with a key.

Public function

void

 

Empty

(
    int32 ExpectedNumElements
)

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

Public function Const

RangedForCon...

 

end()

Public function

RangedForIte...

 

end()

Public function Const

const ValueT...

 

Find

(
    KeyConstPointerType Key
)

Public function

ValueType &#...

 

Find

(
    KeyConstPointerType Key
)

Returns the value associated with a specified key.

Public function

ValueType

 

FindAndRemoveChecked

(
    KeyConstPointerType Key
)

Finds a pair with the specified key, removes it from the map, and returns the value part of the pair.

Public function Const

const ValueT...

 

FindChecked

(
    KeyConstPointerType Key
)

Public function

ValueType &

 

FindChecked

(
    KeyConstPointerType Key
)

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

Public function Const

const KeyTyp...

 

FindKey

(
    ValueInitType Value
)

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

Public function

ValueType &

 

FindOrAdd

(
    KeyType&& Key
)

Public function

ValueType &

 

FindOrAdd

(
    const KeyType& Key
)

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

Public function Const

ValueType

 

FindRef

(
    KeyConstPointerType Key
)

Returns the value associated with a specified key.

Public function Const

void

 

GenerateKeyArray

(
    TArray< KeyType, Allocator >& OutA...
)

Generates an array from the keys in this map.

Public function Const

void

 

GenerateValueArray

(
    TArray< ValueType, Allocator >& Ou...
)

Generates an array from the values in this map.

Public function Const

SIZE_T

 

GetAllocatedSize()

Helper function to return the amount of memory allocated by this container.

Public function Const

int32

 

GetKeys

(
    TArray< KeyType, Allocator >& OutK...
)

Returns the unique keys contained within this map.

Public function Const

int32

 

Num()

Public function

int32

 

Remove

(
    KeyConstPointerType InKey
)

Removes all value associations for a key.

Public function

bool

 

RemoveAndCopyValue

(
    KeyInitType Key,
    ValueType& OutRemovedValue
)

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

Public function

void

 

Reserve

(
    int32 Number
)

Preallocates enough memory to contain Number elements.

Public function

void

 

Reset()

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

Public function

void

 

Shrink()

Shrinks the pair set to avoid slack.

Operators

Name Description

Public function Const

bool

 

operator!=

(
    const TSortedMap& Other
)

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

Public function

ValueType &

 

operator[]

(
    KeyConstPointerType Key
)

Public function Const

const ValueT...

 

operator[]

(
    KeyConstPointerType Key
)

Public function

TSortedMap &

 

operator=

(
    const TSortedMap< KeyType, ValueTyp...
)

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

Public function

TSortedMap &

 

operator=

(
    TSortedMap&&
)

Public function

TSortedMap &

 

operator=

(
    const TSortedMap&
)

Public function

TSortedMap &

 

operator=

(
    TSortedMap< KeyType, ValueType, Oth...
)

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

Public function Const

bool

 

operator==

(
    const TSortedMap& Other
)

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

Classes

Name

Description

Public class

TConstIterator

Const map iterator

Public class

TConstKeyIterator

Iterates over values associated with a specified key in a const map.

Public class

TIterator

Map iterator

Public class

TKeyIterator

Iterates over values associated with a specified key in a map.

Typedefs

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss