TMapBase

The base class of maps from keys to values.

Windows
MacOS
Linux

Inheritance Hierarchy

References

Module

Core

Header

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

Include

#include "Containers/Map.h"

Syntax

template<typename KeyType, typename ValueType, typename SetAllocator, typename KeyFuncs>
class TMapBase

Remarks

The base class of maps from keys to values. Implemented using a TSet of key-value pairs with a custom KeyFuncs, with the same O(1) addition, removal, and finding.

The ByHash() functions are somewhat dangerous but particularly useful in two scenarios: Heterogeneous lookup to avoid creating expensive keys like FString when looking up by const TCHAR*. You must ensure the hash is calculated in the same way as ElementType is hashed. If possible put both ComparableKey and ElementType hash functions next to each other in the same header to avoid bugs when the ElementType hash function is changed. Reducing contention around hash tables protected by a lock. It is often important to incur the cache misses of reading key data and doing the hashing before acquiring the lock.

Variables

Name Description

Protected variable

ElementSetType

 

Pairs

A set of the key-value pairs in the map.

Constructors

Name Description

Protected function

TMapBase()

Protected function

TMapBase

(
    TMapBase&&
)

Protected function

TMapBase

(
    const TMapBase&
)

Protected function

TMapBase

(
    TMapBase< KeyType, ValueType, Other...
)

Constructor for moving elements from a TMap with a different SetAllocator

Protected function

TMapBase

(
    const TMapBase< KeyType, ValueType,...
)

Constructor for copying elements from a TMap with a different SetAllocator

Functions

Name Description

Public function

ValueType &

 

Add

(
    KeyType&& InKey,
    ValueType&& InValue
)

Public function

ValueType &

 

Add

(
    KeyType&& InKey,
    const ValueType& InValue
)

Public function

ValueType &

 

Add

(
    const KeyType& InKey,
    ValueType&& InValue
)

Public function

ValueType &

 

Add

(
    const KeyType& InKey,
    const ValueType& InValue
)

Set the value associated with a key.

Public function

ValueType &

 

Add

(
    TTuple< KeyType, ValueType >&& InK...
)

Public function

ValueType &

 

Add

(
    const TTuple< KeyType, ValueType > ...
)

Set the value associated with a key.

Public function

ValueType &

 

Add

(
    KeyType&& InKey
)

Public function

ValueType &

 

Add

(
    const KeyType& InKey
)

Set a default value associated with a key.

Public function

ValueType &

 

AddByHash

(
    uint32 KeyHash,
    const KeyType& InKey,
    ValueType&& InValue
)

Public function

ValueType &

 

AddByHash

(
    uint32 KeyHash,
    KeyType&& InKey,
    ValueType&& InValue
)

Public function

ValueType &

 

AddByHash

(
    uint32 KeyHash,
    KeyType&& InKey,
    const ValueType& InValue
)

Public function

ValueType &

 

AddByHash

(
    uint32 KeyHash,
    const KeyType& InKey,
    const ValueType& InValue
)

See Add() and class documentation section on ByHash() functions

Public function

ValueType &

 

AddByHash

(
    uint32 KeyHash,
    KeyType&& InKey
)

Public function

ValueType &

 

AddByHash

(
    uint32 KeyHash,
    const KeyType& InKey
)

See Add() and class documentation section on ByHash() functions

Public function Static

void

 

AppendHash

(
    const FPlatformTypeLayoutParameters...,
    FSHA1& Hasher
)

Public function Const

TRangedForCo...

 

begin()

Public function

TRangedForIt...

 

begin()

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

Public function

void

 

Compact()

Compacts the pair set to remove holes

Public function

void

 

CompactStable()

Compacts the pair set to remove holes. Does not change the iteration order of the elements.

Public function Const

bool

 

Contains

(
    KeyConstPointerType Key
)

Check if map contains the specified key.

Public function Const

bool

 

ContainsByHash

(
    uint32 KeyHash,
    const ComparableKey& Key
)

See Contains() and class documentation section on ByHash() functions

Public function Const

void

 

CopyUnfrozen

(
    const FMemoryUnfreezeContent& Cont...,
    void* Dst
)

Public function Const

void

 

CountBytes

(
    FArchive& Ar
)

Track 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

(
    typename TConstKeyIterator::KeyArgu...
)

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

(
    typename TKeyIterator::KeyArgumentT...
)

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
)

Set a default value associated with a key.

Public function

ValueType &

 

EmplaceByHash

(
    uint32 KeyHash,
    InitKeyType&& InKey
)

See Emplace() and class documentation section on ByHash() functions

Public function

ValueType &

 

EmplaceByHash

(
    uint32 KeyHash,
    InitKeyType&& InKey,
    InitValueType&& InValue
)

See Emplace() and class documentation section on ByHash() functions

Public function

void

 

Empty

(
    int32 ExpectedNumElements
)

Removes all elements from the map.

Public function Const

TRangedForCo...

 

end()

Public function

TRangedForIt...

 

end()

Public function Const

TMap< KeyTyp...

 

FilterByPredicate

(
    Predicate Pred
)

Filters the elements in the map based on a predicate functor.

Public function Const

const ValueT...

 

Find

(
    KeyConstPointerType Key
)

Public function

ValueType &#...

 

Find

(
    KeyConstPointerType Key
)

Find the value associated with a specified key.

Public function Const

const ValueT...

 

FindByHash

(
    uint32 KeyHash,
    const ComparableKey& Key
)

Public function

ValueType &#...

 

FindByHash

(
    uint32 KeyHash,
    const ComparableKey& Key
)

See Find() and class documentation section on ByHash() functions

Public function

ValueType &

 

FindChecked

(
    KeyConstPointerType Key
)

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

Public function Const

const ValueT...

 

FindChecked

(
    KeyConstPointerType Key
)

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

Public function Const

const KeyTyp...

 

FindKey

(
    ValueInitType Value
)

Find the key associated with the specified value.

The time taken is O(N) in the number of pairs.

Public function

ValueType &

 

FindOrAdd

(
    KeyType&& Key,
    ValueType&& Value
)

Public function

ValueType &

 

FindOrAdd

(
    const KeyType& Key
)

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

Public function

ValueType &

 

FindOrAdd

(
    KeyType&& Key,
    const ValueType& Value
)

Public function

ValueType &

 

FindOrAdd

(
    const KeyType& Key,
    ValueType&& Value
)

Public function

ValueType &

 

FindOrAdd

(
    const KeyType& Key,
    const ValueType& Value
)

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

Public function

ValueType &

 

FindOrAdd

(
    KeyType&& Key
)

Public function

ValueType &

 

FindOrAddByHash

(
    uint32 KeyHash,
    KeyType&& Key
)

Public function

ValueType &

 

FindOrAddByHash

(
    uint32 KeyHash,
    const KeyType& Key,
    const ValueType& Value
)

See FindOrAdd() and class documentation section on ByHash() functions

Public function

ValueType &

 

FindOrAddByHash

(
    uint32 KeyHash,
    KeyType&& Key,
    const ValueType& Value
)

Public function

ValueType &

 

FindOrAddByHash

(
    uint32 KeyHash,
    KeyType&& Key,
    ValueType&& Value
)

Public function

ValueType &

 

FindOrAddByHash

(
    uint32 KeyHash,
    const KeyType& Key
)

See FindOrAdd() and class documentation section on ByHash() functions

Public function

ValueType &

 

FindOrAddByHash

(
    uint32 KeyHash,
    const KeyType& Key,
    ValueType&& Value
)

Public function Const

ValueType

 

FindRef

(
    KeyConstPointerType Key
)

Find the value associated with a specified key.

Public function Const

void

 

GenerateKeyArray

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

Generate an array from the keys in this map.

Public function Const

void

 

GenerateValueArray

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

Generate an array from the values in this map.

Public function Const

uint32

 

GetAllocatedSize()

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

Public function Const

int32

 

GetKeys

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

Get the unique keys contained within this map.

Public function Const

int32

 

GetKeys

(
    TSet< KeyType, Allocator >& OutKey...
)

Get the unique keys contained within this map.

Public function Const

int32

 

Num()

Public function Const

bool

 

OrderIndependentCompareEqual

(
    const TMapBase& Other
)

Compare this map with another for equality.

Public function

int32

 

Remove

(
    KeyConstPointerType InKey
)

Remove all value associations for a key.

Public function

int32

 

RemoveByHash

(
    uint32 KeyHash,
    const ComparableKey& Key
)

See Remove() and class documentation section on ByHash() functions

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.

Public function Const

void

 

WriteMemoryImage

(
    FMemoryImageWriter& Writer
)

Operators

Name Description

Protected function

TMapBase &

 

operator=

(
    const TMapBase< KeyType, ValueType,...
)

Assignment operator for copying elements from a TMap with a different SetAllocator

Protected function

TMapBase &

 

operator=

(
    TMapBase&&
)

Protected function

TMapBase &

 

operator=

(
    const TMapBase&
)

Protected function

TMapBase &

 

operator=

(
    TMapBase< KeyType, ValueType, Other...
)

Assignment operator for moving elements from a TMap with a different SetAllocator

Classes

Name

Description

Protected class

TBaseIterator

The base of TMapBase iterators.

Protected class

TBaseKeyIterator

The base type of iterators that iterate over the values associated with a specified key.

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

Constants

Name

Description

SupportsFreezeMemoryImage

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