engine
 
载入中...
搜索中...
未找到
类 | Public 类型 | Public 成员函数 | 友元 | 所有成员列表
TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate > 模板类 参考

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

#include <SortedMap.h>

类

class  TConstIterator
 Const map iterator 更多...
 
class  TConstKeyIterator
 Iterates over values associated with a specified key in a const map. 更多...
 
class  TIterator
 Map iterator 更多...
 
class  TKeyIterator
 Iterates over values associated with a specified key in a map. 更多...
 

Public 类型

typedef ElementArrayType::RangedForIteratorType RangedForIteratorType
 Ranged For iterators. 更多...
 

Public 成员函数

FORCEINLINE ValueType & Add (const KeyType &InKey)
 Sets a default value associated with a key. 更多...
 
FORCEINLINE ValueType & Add (const KeyType &InKey, const ValueType &InValue)
 Sets the value associated with a key. 更多...
 
template<typename OtherArrayAllocator , typename OtherSortPredicate >
void Append (const TSortedMap< KeyType, ValueType, OtherArrayAllocator, OtherSortPredicate > &OtherMap)
 Add all items from another map to our map (if any keys are in both, the value from the other map wins). 更多...
 
template<typename OtherArrayAllocator , typename OtherSortPredicate >
void Append (TSortedMap< KeyType, ValueType, OtherArrayAllocator, OtherSortPredicate > &&OtherMap)
 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. 更多...
 
FORCEINLINE RangedForIteratorType begin ()
 DO NOT USE DIRECTLY STL-like iterators to enable range-based for loop support.
 
FORCEINLINE bool Contains (KeyConstPointerType Key) const
 Checks if map contains the specified key. 更多...
 
FORCEINLINE void CountBytes (FArchive &Ar) const
 Tracks the container's memory use through an archive.
 
FORCEINLINE TConstIterator CreateConstIterator () const
 Creates a const iterator over all the pairs in this map
 
FORCEINLINE TConstKeyIterator CreateConstKeyIterator (KeyInitType InKey) const
 Creates a const iterator over the values associated with a specified key in a map. 更多...
 
FORCEINLINE TIterator CreateIterator ()
 Creates an iterator over all the pairs in this map
 
FORCEINLINE TKeyIterator CreateKeyIterator (KeyInitType InKey)
 Creates an iterator over the values associated with a specified key in a map. 更多...
 
void Dump (FOutputDevice &Ar)
 Describes the map's contents through an output device. 更多...
 
template<typename InitKeyType >
ValueType & Emplace (InitKeyType &&InKey)
 Sets a default value associated with a key. 更多...
 
template<typename InitKeyType , typename InitValueType >
ValueType & Emplace (InitKeyType &&InKey, InitValueType &&InValue)
 Sets the value associated with a key. 更多...
 
FORCEINLINE void Empty (int32 ExpectedNumElements=0)
 Removes all elements from the map, potentially leaving space allocated for an expected number of elements about to be added. 更多...
 
FORCEINLINE ValueType * Find (KeyConstPointerType Key)
 Returns the value associated with a specified key. 更多...
 
FORCEINLINE ValueType FindAndRemoveChecked (KeyConstPointerType Key)
 Finds a pair with the specified key, removes it from the map, and returns the value part of the pair. 更多...
 
FORCEINLINE ValueType & FindChecked (KeyConstPointerType Key)
 Returns a reference to the value associated with a specified key. 更多...
 
const KeyType * FindKey (ValueInitType Value) const
 Returns the key associated with the specified value. 更多...
 
FORCEINLINE ValueType & FindOrAdd (const KeyType &Key)
 Returns the value associated with a specified key, or if none exists, adds a value using the default constructor. 更多...
 
FORCEINLINE ValueType FindRef (KeyConstPointerType Key) const
 Returns the value associated with a specified key. 更多...
 
template<typename Allocator >
void GenerateKeyArray (TArray< KeyType, Allocator > &OutArray) const
 Generates an array from the keys in this map.
 
template<typename Allocator >
void GenerateValueArray (TArray< ValueType, Allocator > &OutArray) const
 Generates an array from the values in this map.
 
FORCEINLINE SIZE_T GetAllocatedSize () const
 Helper function to return the amount of memory allocated by this container. 更多...
 
template<typename Allocator >
int32 GetKeys (TArray< KeyType, Allocator > &OutKeys) const
 Returns the unique keys contained within this map. 更多...
 
FORCEINLINE int32 Num () const
 
FORCEINLINE bool operator!= (const TSortedMap &Other) const
 Inequality operator. 更多...
 
template<typename OtherArrayAllocator >
TSortedMap & operator= (const TSortedMap< KeyType, ValueType, OtherArrayAllocator, SortPredicate > &Other)
 Assignment operator for copying elements from a TSortedMap with a different ArrayAllocator.
 
template<typename OtherArrayAllocator >
TSortedMap & operator= (TSortedMap< KeyType, ValueType, OtherArrayAllocator, SortPredicate > &&Other)
 Assignment operator for moving elements from a TSortedMap with a different ArrayAllocator.
 
FORCEINLINE bool operator== (const TSortedMap &Other) const
 Equality operator. 更多...
 
FORCEINLINE int32 Remove (KeyConstPointerType InKey)
 Removes all value associations for a key. 更多...
 
FORCEINLINE bool RemoveAndCopyValue (KeyInitType Key, ValueType &OutRemovedValue)
 Removes the pair with the specified key and copies the value that was removed to the ref parameter. 更多...
 
FORCEINLINE void Reserve (int32 Number)
 Preallocates enough memory to contain Number elements.
 
FORCEINLINE void Reset ()
 Efficiently empties out the map but preserves all allocations and capacities.
 
FORCEINLINE void Shrink ()
 Shrinks the pair set to avoid slack.
 
template<typename OtherArrayAllocator >
 TSortedMap (const TSortedMap< KeyType, ValueType, OtherArrayAllocator, SortPredicate > &Other)
 Constructor for copying elements from a TSortedMap with a different ArrayAllocator.
 
template<typename OtherArrayAllocator >
 TSortedMap (TSortedMap< KeyType, ValueType, OtherArrayAllocator, SortPredicate > &&Other)
 Constructor for moving elements from a TSortedMap with a different ArrayAllocator.
 

友元

FORCEINLINE friend FArchive & operator<< (FArchive &Ar, TSortedMap &Map)
 Serializer.
 

详细描述

template<typename KeyType, typename ValueType, typename ArrayAllocator, typename SortPredicate>
class TSortedMap< KeyType, ValueType, 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.

成员类型定义说明

◆ RangedForIteratorType

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
typedef ElementArrayType::RangedForIteratorType TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::RangedForIteratorType

Ranged For iterators.

Unlike normal TMap these are not the same as the normal iterator for performance reasons

成员函数说明

◆ Add() [1/2]

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
FORCEINLINE ValueType & TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::Add ( const KeyType &  InKey)
inline

Sets a default value associated with a key.

参数
InKeyThe key to associate the value with.
返回
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/2]

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
FORCEINLINE ValueType & TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::Add ( const KeyType &  InKey,
const ValueType &  InValue 
)
inline

Sets the value associated with a key.

参数
InKeyThe key to associate the value with.
InValueThe value to associate with the key.
返回
A reference to the value as stored in the map (only valid until the next change to any key in the map).

◆ Append() [1/2]

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
template<typename OtherArrayAllocator , typename OtherSortPredicate >
void TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::Append ( const TSortedMap< KeyType, ValueType, OtherArrayAllocator, OtherSortPredicate > &  OtherMap)
inline

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

参数
OtherMapThe other map of items to add.

◆ Append() [2/2]

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
template<typename OtherArrayAllocator , typename OtherSortPredicate >
void TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::Append ( TSortedMap< KeyType, ValueType, OtherArrayAllocator, OtherSortPredicate > &&  OtherMap)
inline

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.

参数
OtherMapThe other map of items to move the elements from.

◆ Contains()

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
FORCEINLINE bool TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::Contains ( KeyConstPointerType  Key) const
inline

Checks if map contains the specified key.

参数
KeyThe key to check for.
返回
true if the map contains the key.

◆ CreateConstKeyIterator()

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
FORCEINLINE TConstKeyIterator TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::CreateConstKeyIterator ( KeyInitType  InKey) const
inline

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

◆ CreateKeyIterator()

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
FORCEINLINE TKeyIterator TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::CreateKeyIterator ( KeyInitType  InKey)
inline

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

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
void TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::Dump ( FOutputDevice &  Ar)
inline

Describes the map's contents through an output device.

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

◆ Emplace() [1/2]

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
template<typename InitKeyType >
ValueType & TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::Emplace ( InitKeyType &&  InKey)
inline

Sets a default value associated with a key.

参数
InKeyThe key to associate the value with.
返回
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]

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
template<typename InitKeyType , typename InitValueType >
ValueType & TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::Emplace ( InitKeyType &&  InKey,
InitValueType &&  InValue 
)
inline

Sets the value associated with a key.

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

◆ Empty()

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
FORCEINLINE void TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::Empty ( int32  ExpectedNumElements = 0)
inline

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

参数
ExpectedNumElementsThe number of elements about to be added to the set.

◆ Find()

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
FORCEINLINE ValueType * TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::Find ( KeyConstPointerType  Key)
inline

Returns the value associated with a specified key.

参数
KeyThe key to search for.
返回
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).

◆ FindAndRemoveChecked()

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
FORCEINLINE ValueType TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::FindAndRemoveChecked ( KeyConstPointerType  Key)
inline

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.

参数
KeyThe key to search for
返回
Whether or not the key was found

◆ FindChecked()

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
FORCEINLINE ValueType & TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::FindChecked ( KeyConstPointerType  Key)
inline

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

参数
KeyThe key to search for.
返回
The value associated with the specified key, or triggers an assertion if the key does not exist.

◆ FindKey()

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
const KeyType * TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::FindKey ( ValueInitType  Value) const
inline

Returns the key associated with the specified value.

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

参数
ValueThe value to search for.
返回
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()

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
FORCEINLINE ValueType & TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::FindOrAdd ( const KeyType &  Key)
inline

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

参数
KeyThe key to search for.
返回
A reference to the value associated with the specified key.

◆ FindRef()

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
FORCEINLINE ValueType TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::FindRef ( KeyConstPointerType  Key) const
inline

Returns the value associated with a specified key.

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

◆ GetAllocatedSize()

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
FORCEINLINE SIZE_T TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::GetAllocatedSize ( ) const
inline

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.

返回
number of bytes allocated by this container.

◆ GetKeys()

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
template<typename Allocator >
int32 TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::GetKeys ( TArray< KeyType, Allocator > &  OutKeys) const
inline

Returns the unique keys contained within this map.

参数
OutKeysUpon return, contains the set of unique keys in this map.
返回
The number of unique keys in the map.

◆ Num()

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
FORCEINLINE int32 TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::Num ( ) const
inline
返回
The number of elements in the map.

◆ operator!=()

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
FORCEINLINE bool TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::operator!= ( const TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate > &  Other) const
inline

Inequality operator.

This is efficient because pairs are always sorted.

◆ operator==()

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
FORCEINLINE bool TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::operator== ( const TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate > &  Other) const
inline

Equality operator.

This is efficient because pairs are always sorted.

◆ Remove()

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
FORCEINLINE int32 TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::Remove ( KeyConstPointerType  InKey)
inline

Removes all value associations for a key.

参数
InKeyThe key to remove associated values for.
返回
The number of values that were associated with the key.

◆ RemoveAndCopyValue()

template<typename KeyType , typename ValueType , typename ArrayAllocator , typename SortPredicate >
FORCEINLINE bool TSortedMap< KeyType, ValueType, ArrayAllocator, SortPredicate >::RemoveAndCopyValue ( KeyInitType  Key,
ValueType &  OutRemovedValue 
)
inline

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

参数
KeyThe key to search for
OutRemovedValueIf found, the value that was removed (not modified if the key was not found)
返回
Whether or not the key was found

该类的文档由以下文件生成: