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, OtherSetAllocator, KeyFuncs >&& Other
)

Constructor for moving elements from a TMap with a different SetAllocator

Protected function

TMapBase

(
    const TMapBase< KeyType, ValueType, OtherSetAllocator, KeyFuncs >& Other
)

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 >&& InKeyValue
)

Public function

ValueType &

 

Add

(
    const TTuple< KeyType, ValueType >& InKeyValue
)

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,
    KeyType&& InKey,
    const ValueType& InValue
)

Public function

ValueType &

 

AddByHash

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

Public function

ValueType &

 

AddByHash

(
    uint32 KeyHash,
    const KeyType& InKey,
    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 Const

TRangedForConstIterator

 

begin()

Public function

TRangedForIterator

 

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

 

CountBytes

(
    FArchive& Ar
)

Track the container's memory use through an archive.

Public function Const

TConstIterator

 

CreateConstIterator()

Creates a const iterator over all the pairs in this map

Public function Const

TConstKeyIterator

 

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
)

Set a default value associated with a key.

Public function

ValueType &

 

Emplace

(
    InitKeyType&& InKey,
    InitValueType&& InValue
)

Sets the 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

TRangedForConstIterator

 

end()

Public function

TRangedForIterator

 

end()

Public function

ValueType *

 

Find

(
    KeyConstPointerType Key
)

Find the value associated with a specified key.

Public function Const

const ValueType *

 

Find

(
    KeyConstPointerType Key
)

Public function

ValueType *

 

FindByHash

(
    uint32 KeyHash,
    const ComparableKey& Key
)

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

Public function Const

const ValueType *

 

FindByHash

(
    uint32 KeyHash,
    const ComparableKey& Key
)

Public function Const

const ValueType &

 

FindChecked

(
    KeyConstPointerType Key
)

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

Public function

ValueType &

 

FindChecked

(
    KeyConstPointerType Key
)

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

Public function Const

const KeyType *

 

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

(
    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
)

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,
    ValueType&& Value
)

Public function

ValueType &

 

FindOrAdd

(
    const KeyType& Key,
    ValueType&& Value
)

Public function

ValueType &

 

FindOrAdd

(
    KeyType&& Key,
    const 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,
    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,
    const KeyType& Key,
    ValueType&& Value
)

Public function

ValueType &

 

FindOrAddByHash

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

Public function

ValueType &

 

FindOrAddByHash

(
    uint32 KeyHash,
    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 >& OutArray
)

Generate an array from the keys in this map.

Public function Const

void

 

GenerateValueArray

(
    TArray< ValueType, Allocator >& OutArray
)

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 >& OutKeys
)

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.

Operators

Name Description

Protected function

TMapBase &

 

operator=

(
    TMapBase&&
)

Protected function

TMapBase &

 

operator=

(
    const TMapBase&
)

Protected function

TMapBase &

 

operator=

(
    TMapBase< KeyType, ValueType, OtherSetAllocator, KeyFuncs >&& Other
)

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

Protected function

TMapBase &

 

operator=

(
    const TMapBase< KeyType, ValueType, OtherSetAllocator, KeyFuncs >& Other
)

Assignment operator for copying 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

Select Skin
Light
Dark

Welcome to the new Unreal Engine 4 Documentation site!

We're working on lots of new features including a feedback system so you can tell us how we are doing. It's not quite ready for use in the wild yet, so head over to the Documentation Feedback forum to tell us about this page or call out any issues you are encountering in the meantime.

We'll be sure to let you know when the new system is up and running.

Post Feedback