![]() |
Plasma Engine
2.0
|
Implementation of a hashtable which stores key/value pairs. More...
#include <HashTable.h>
Inherited by plHashTable< plUuid, plSubAsset >, plHashTable< const char *, plActionDescriptorHandle >, plHashTable< plHybridString, plSharedPtr< plAnimGraphSharedBoneWeights > >, plHashTable< plHashedString, plAnimController::AnimClipInfo >, plHashTable< plArchiveStoredString, plUInt32 >, plHashTable< plUuid, plAssetInfo * >, plHashTable< plUuid, plEditorEngineSyncObject * >, plHashTable< plHashedString, plBlackboard::Entry >, plHashTable< plHashedString, plSharedPtr< plBlackboard > >, plHashTable< plHashedString, plInt32 >, plHashTable< plHashedString, float >, plHashTable< plHashedString, plHybridString >, plHashTable< plHashedString, bool >, plHashTable< plVariant, plPropertyUiState >, plHashTable< const void *, plUInt32 >, plHashTable< plHybridString, DependencyListType >, plHashTable< vk::DescriptorType, float >, plHashTable< plUuid, plDocumentNodeManager::NodeInternal >, plHashTable< plUuid, plUniquePtr< plConnection > >, plHashTable< plUuid, const plDocumentObject * >, plHashTable< plUuid, plAssetDocument * >, plHashTable< plUuid, HandleType >, plHashTable< const plRTTI *, ShapeIconInfo >, plHashTable< plUuid, plEngineProcessDocumentContext * >, plHashTable< plUInt32, plSmallArray< plExpressionAST::Node *, 1 > >, plHashTable< const plExpressionAST::Node *, plUInt32 >, plHashTable< plExpressionAST::Node *, plExpressionAST::Node * >, plHashTable< plHashedString, plUInt32 >, plHashTable< plHashedString, plExpressionAST::Node * >, plHashTable< plHashedString, plHybridArray< plExpression::FunctionDesc, 1 > >, plHashTable< plUInt32, plFileserveClientContext >, plHashTable< plUInt32, plGALBufferResourceViewHandle >, plHashTable< plUInt32, plGALBufferUnorderedAccessViewHandle >, plHashTable< plHashedString, plGALSamplerStateCreationDescription >, plHashTable< plUInt32, plGALTextureResourceViewHandle >, plHashTable< plUInt32, plGALRenderTargetViewHandle >, plHashTable< plUInt32, plGALTextureUnorderedAccessViewHandle >, plHashTable< plHashedString, plTypeVersionInfo >, plHashTable< void *, plUInt32 >, plHashTable< plHybridString, plGALTextureHandle >, plHashTable< plGALShaderHandle, plGALVertexDeclarationHandle >, plHashTable< plImageCopyVulkan::RenderPassCacheKey, vk::RenderPass >, plHashTable< plImageCopyVulkan::ImageViewCacheKey, vk::ImageView >, plHashTable< vk::Image, plImageCopyVulkan::ImageViewCacheValue >, plHashTable< plImageCopyVulkan::FramebufferCacheKey, vk::Framebuffer >, plHashTable< plShaderUtils::plBuiltinShaderType, plShaderUtils::plBuiltinShader >, plHashTable< plTypelessResourceHandle, plHybridArray >, plHashTable< T, typename DataMap::Iterator >, plHashTable< plString, plVariant >, plHashTable< const plRTTI *, CreateObjectFunc >, plHashTable< plHashedString, plHashedString >, plHashTable< plHashedString, plVariant >, plHashTable< plHashedString, plTypedResourceHandle< class plTexture2DResource > >, plHashTable< plHashedString, plTypedResourceHandle >, plHashTable< uint32_t, ExportedSharedPool >, plHashTable< plHashedString, plMeshResourceDescriptor::BoneData >, plHashTable< KEY, VALUE >, plHashTable< XrPath, plHybridString >, plHashTable< const plRTTI *, plWorldModule * >, plHashTable< plInt64, PathStateType >, plHashTable< plStringView, plPhantomRTTI * >, plHashTable< const plDocumentObject *, plUniquePtr< plProcGenNodeBase > >, plHashTable< DocObjAndOutput, plExpressionAST::Node * >, plHashTable< plUInt64, plProcPlacementComponent::OutputContext::TileIndexAndAge >, plHashTable< plUInt32, float >, plHashTable< plUuid, plHybridArray< plPropertyReference, 1 > >, plHashTable< const plRTTI *, plQtDocumentTreeModelAdapter * >, plHashTable< plUInt32, FileOpData >, plHashTable< plUInt32, ClientData >, plHashTable< plUuid, plUInt32 >, plHashTable< plUuid, QSharedPointer< plQtProxy > >, plHashTable< plUInt64, ResourceData >, plHashTable< plHybridString, plReflectedTypeStorageManager::ReflectedTypeStorageMapping::StorageInfo >, plHashTable< plUInt32, plRemoteMessageQueue >, plHashTable< plUInt64, plGALTextureResourceViewHandle >, plHashTable< plUInt64, plGALTextureUnorderedAccessViewHandle >, plHashTable< plUInt64, plGALSamplerStateHandle >, plHashTable< plUInt64, plGALBufferResourceViewHandle >, plHashTable< plUInt64, plGALBufferUnorderedAccessViewHandle >, plHashTable< plUInt64, BoundConstantBuffer >, plHashTable< const plRTTI *, plUInt32 >, plHashTable< plRenderPipelinePassConnection *, plUInt32 >, plHashTable< plHashedString, const plRenderPipelineNodePin * >, plHashTable< plTempHashedString, plResource * >, plHashTable< const plRTTI *, plResourceManager::LoadedResources >, plHashTable< plTempHashedString, const plRTTI * >, plHashTable< plTempHashedString, plHashedString >, plHashTable< plHashedString, plDelegate >, plHashTable< plUuid, plRttiConverterObject >, plHashTable< const void *, plUuid >, plHashTable< plUuid, LayerInfo >, plHashTable< plScriptWorldModule::FunctionContext, typename DataMap::Iterator >, plHashTable< plScriptInstance *, plSmallArray< plScriptCoroutineHandle, 8 > >, plHashTable< plComponentHandle, typename DataMap::Iterator >, plHashTable< LightAndRefView, plUInt32 >, plHashTable< plTempHashedString, bool >, plHashTable< plTempHashedString, plInt64 >, plHashTable< plTempHashedString, double >, plHashTable< plTempHashedString, plVec3Template >, plHashTable< plTempHashedString, plColor >, plHashTable< plTempHashedString, plHybridString >, plHashTable< plUInt32, plTypeScriptBinding::FunctionBinding >, plHashTable< plUInt32, plTypeScriptBinding::PropertyBinding >, plHashTable< duk_context *, plWorld * >, plHashTable< const plRTTI *, const plVariantTypeInfo * >, plHashTable< const plRTTI *, DefaultInput >, plHashTable< const plVisualScriptPin *, plUInt32 >, plHashTable< plUInt32, DataDesc >, plHashTable< plVariant, plUInt32 >, plHashTable< plHashedString, plVisualScriptInstanceData >, plHashTable< const plDocumentObject *, plEnum< plVisualScriptDataType > >, plHashTable< const plVisualScriptPin *, plEnum< plVisualScriptDataType > >, plHashTable< plHashedString, Value >, plHashTable< const plRTTI *, plWorldModuleTypeId >, plHashTable< plHybridString, plHybridString >, plHashTable< plUuid, plGameObjectHandle >, plHashTable< plUuid, plComponentHandle >, plHashTable< const plRTTI *, Components >, and plHashTable< KeyType, ValueType, Hasher, AllocatorWrapper >.
Public Types | |
using | Iterator = plHashTableBaseIterator<KeyType, ValueType, Hasher> |
using | ConstIterator = plHashTableBaseConstIterator<KeyType, ValueType, Hasher> |
Public Member Functions | |
bool | operator== (const plHashTableBase< KeyType, ValueType, Hasher > &rhs) const |
Compares this table to another table. | |
PL_ADD_DEFAULT_OPERATOR_NOTEQUAL (const plHashTableBase< KeyType, ValueType, Hasher > &) | |
void | Reserve (plUInt32 uiCapacity) |
Expands the hashtable by over-allocating the internal storage so that the load factor is lower or equal to 60% when inserting the given number of entries. | |
void | Compact () |
Tries to compact the hashtable to avoid wasting memory. | |
plUInt32 | GetCount () const |
Returns the number of active entries in the table. | |
bool | IsEmpty () const |
Returns true, if the hashtable does not contain any elements. | |
void | Clear () |
Clears the table. | |
template<typename CompatibleKeyType , typename CompatibleValueType > | |
bool | Insert (CompatibleKeyType &&key, CompatibleValueType &&value, ValueType *out_pOldValue=nullptr) |
Inserts the key value pair or replaces value if an entry with the given key already exists. | |
template<typename CompatibleKeyType > | |
bool | Remove (const CompatibleKeyType &key, ValueType *out_pOldValue=nullptr) |
Removes the entry with the given key. Returns whether an entry was removed and optionally writes out the old value to out_oldValue. | |
Iterator | Remove (const Iterator &pos) |
Erases the key/value pair at the given Iterator. Returns an iterator to the element after the given iterator. | |
void | Remove (const ConstIterator &pos)=delete |
Cannot remove an element with just a plHashTableBaseConstIterator. | |
template<typename CompatibleKeyType > | |
bool | TryGetValue (const CompatibleKeyType &key, ValueType &out_value) const |
Returns whether an entry with the given key was found and if found writes out the corresponding value to out_value. | |
template<typename CompatibleKeyType > | |
bool | TryGetValue (const CompatibleKeyType &key, const ValueType *&out_pValue) const |
Returns whether an entry with the given key was found and if found writes out the pointer to the corresponding value to out_pValue. | |
template<typename CompatibleKeyType > | |
bool | TryGetValue (const CompatibleKeyType &key, ValueType *&out_pValue) const |
Returns whether an entry with the given key was found and if found writes out the pointer to the corresponding value to out_pValue. | |
template<typename CompatibleKeyType > | |
ConstIterator | Find (const CompatibleKeyType &key) const |
Searches for key, returns a plHashTableBaseConstIterator to it or an invalid iterator, if no such key is found. O(1) operation. | |
template<typename CompatibleKeyType > | |
Iterator | Find (const CompatibleKeyType &key) |
Searches for key, returns an Iterator to it or an invalid iterator, if no such key is found. O(1) operation. | |
template<typename CompatibleKeyType > | |
const ValueType * | GetValue (const CompatibleKeyType &key) const |
Returns a pointer to the value of the entry with the given key if found, otherwise returns nullptr. | |
template<typename CompatibleKeyType > | |
ValueType * | GetValue (const CompatibleKeyType &key) |
Returns a pointer to the value of the entry with the given key if found, otherwise returns nullptr. | |
ValueType & | operator[] (const KeyType &key) |
Returns the value to the given key if found or creates a new entry with the given key and a default constructed value. | |
ValueType & | FindOrAdd (const KeyType &key, bool *out_pExisted=nullptr) |
Returns the value stored at the given key. If none exists, one is created. bExisted indicates whether an element needed to be created. | |
template<typename CompatibleKeyType > | |
bool | Contains (const CompatibleKeyType &key) const |
Returns if an entry with given key exists in the table. | |
Iterator | GetIterator () |
Returns an Iterator to the very first element. | |
Iterator | GetEndIterator () |
Returns an Iterator to the first element that is not part of the hash-table. Needed to support range based for loops. | |
ConstIterator | GetIterator () const |
Returns a constant Iterator to the very first element. | |
ConstIterator | GetEndIterator () const |
Returns a plHashTableBaseConstIterator to the first element that is not part of the hash-table. Needed to support range based for loops. | |
plAllocator * | GetAllocator () const |
Returns the allocator that is used by this instance. | |
plUInt64 | GetHeapMemoryUsage () const |
Returns the amount of bytes that are currently allocated on the heap. | |
void | Swap (plHashTableBase< KeyType, ValueType, Hasher > &other) |
Swaps this map with the other one. | |
template<typename CompatibleKeyType , typename CompatibleValueType > | |
bool | Insert (CompatibleKeyType &&key, CompatibleValueType &&value, V *out_pOldValue) |
template<typename CompatibleKeyType > | |
bool | Remove (const CompatibleKeyType &key, V *out_pOldValue) |
template<typename CompatibleKeyType > | |
bool | TryGetValue (const CompatibleKeyType &key, V &out_value) const |
template<typename CompatibleKeyType > | |
bool | TryGetValue (const CompatibleKeyType &key, const V *&out_pValue) const |
template<typename CompatibleKeyType > | |
bool | TryGetValue (const CompatibleKeyType &key, V *&out_pValue) const |
template<typename CompatibleKeyType > | |
const V * | GetValue (const CompatibleKeyType &key) const |
template<typename CompatibleKeyType > | |
V * | GetValue (const CompatibleKeyType &key) |
template<typename CompatibleKeyType > | |
PL_FORCE_INLINE bool | Contains (const CompatibleKeyType &key) const |
template<typename CompatibleKeyType > | |
PL_ALWAYS_INLINE plUInt32 | FindEntry (const CompatibleKeyType &key) const |
Protected Member Functions | |
plHashTableBase (plAllocator *pAllocator) | |
Creates an empty hashtable. Does not allocate any data yet. | |
plHashTableBase (const plHashTableBase< KeyType, ValueType, Hasher > &rhs, plAllocator *pAllocator) | |
Creates a copy of the given hashtable. | |
plHashTableBase (plHashTableBase< KeyType, ValueType, Hasher > &&rhs, plAllocator *pAllocator) | |
Moves data from an existing hashtable into this one. | |
~plHashTableBase () | |
Destructor. | |
void | operator= (const plHashTableBase< KeyType, ValueType, Hasher > &rhs) |
Copies the data from another hashtable into this one. | |
void | operator= (plHashTableBase< KeyType, ValueType, Hasher > &&rhs) |
Moves data from an existing hashtable into this one. | |
Friends | |
struct | plHashTableBaseConstIterator< KeyType, ValueType, Hasher > |
struct | plHashTableBaseIterator< KeyType, ValueType, Hasher > |
Implementation of a hashtable which stores key/value pairs.
The hashtable maps keys to values by using the hash of the key as an index into the table. This implementation uses linear-probing to resolve hash collisions which means all key/value pairs are stored in a linear array. All insertion/erasure/lookup functions take O(1) time if the table does not need to be expanded, which happens when the load gets greater than 60%. The hash function can be customized by providing a Hasher helper class like plHashHelper.
void plHashTableBase< K, V, H >::Compact | ( | ) |
Tries to compact the hashtable to avoid wasting memory.
The resulting capacity is at least 'GetCount' (no elements get removed). Will deallocate all data, if the hashtable is empty.
bool plHashTableBase< KeyType, ValueType, Hasher >::Insert | ( | CompatibleKeyType && | key, |
CompatibleValueType && | value, | ||
ValueType * | out_pOldValue = nullptr ) |
Inserts the key value pair or replaces value if an entry with the given key already exists.
Returns true if an existing value was replaced and optionally writes out the old value to out_oldValue.