Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
LockFreeHashMap< Key, Value > Class Template Reference

#include <LockFreeHashMap.h>

Inheritance diagram for LockFreeHashMap< Key, Value >:
NonCopyable

Classes

struct  Iterator
 Non-const iterator. More...
 
class  KeyValue
 A key / value pair that is inserted in the map. More...
 

Public Types

using MapType = LockFreeHashMap< Key, Value >
 

Public Member Functions

 LockFreeHashMap (LFHMAllocator &inAllocator)
 Destructor.
 
 ~LockFreeHashMap ()
 
void Init (uint32 inMaxBuckets)
 
void Clear ()
 
uint32 GetNumBuckets () const
 Get the current amount of buckets that the map is using.
 
uint32 GetMaxBuckets () const
 Get the maximum amount of buckets that this map supports.
 
void SetNumBuckets (uint32 inNumBuckets)
 
template<class... Params>
KeyValueCreate (LFHMAllocatorContext &ioContext, const Key &inKey, uint64 inKeyHash, int inExtraBytes, Params &&... inConstructorParams)
 
const KeyValueFind (const Key &inKey, uint64 inKeyHash) const
 Find an element, returns null if not found.
 
uint32 ToHandle (const KeyValue *inKeyValue) const
 Get convert key value pair to uint32 handle.
 
const KeyValueFromHandle (uint32 inHandle) const
 Convert uint32 handle back to key and value.
 
void GetAllKeyValues (Array< const KeyValue * > &outAll) const
 Get all key/value pairs.
 
Iterator begin ()
 
Iterator end ()
 
- Public Member Functions inherited from NonCopyable
 NonCopyable ()=default
 
 NonCopyable (const NonCopyable &)=delete
 
void operator= (const NonCopyable &)=delete
 

Static Public Attributes

static const uint32 cInvalidHandle = uint32(-1)
 Value of an invalid handle.
 

Detailed Description

template<class Key, class Value>
class LockFreeHashMap< Key, Value >

Very simple lock free hash map that only allows insertion, retrieval and provides a fixed amount of buckets and fixed storage. Note: This class currently assumes key and value are simple types that need no calls to the destructor.

Member Typedef Documentation

◆ MapType

template<class Key , class Value >
using LockFreeHashMap< Key, Value >::MapType = LockFreeHashMap<Key, Value>

Constructor & Destructor Documentation

◆ LockFreeHashMap()

template<class Key , class Value >
LockFreeHashMap< Key, Value >::LockFreeHashMap ( LFHMAllocator inAllocator)
inlineexplicit

Destructor.

◆ ~LockFreeHashMap()

template<class Key , class Value >
LockFreeHashMap< Key, Value >::~LockFreeHashMap ( )

Member Function Documentation

◆ begin()

template<class Key , class Value >
LockFreeHashMap< Key, Value >::Iterator LockFreeHashMap< Key, Value >::begin ( )

Iterate over the map, note that it is not safe to do this in parallel to Clear(). It is safe to do this while adding elements to the map, but newly added elements may or may not be returned by the iterator.

◆ Clear()

template<class Key , class Value >
void LockFreeHashMap< Key, Value >::Clear ( )

Remove all elements. Note that this cannot happen simultaneously with adding new elements.

◆ Create()

template<class Key , class Value >
template<class... Params>
LockFreeHashMap< Key, Value >::KeyValue * LockFreeHashMap< Key, Value >::Create ( LFHMAllocatorContext ioContext,
const Key &  inKey,
uint64  inKeyHash,
int  inExtraBytes,
Params &&...  inConstructorParams 
)
inline

Insert a new element, returns null if map full. Multiple threads can be inserting in the map at the same time.

◆ end()

template<class Key , class Value >
LockFreeHashMap< Key, Value >::Iterator LockFreeHashMap< Key, Value >::end ( )

◆ Find()

template<class Key , class Value >
const LockFreeHashMap< Key, Value >::KeyValue * LockFreeHashMap< Key, Value >::Find ( const Key &  inKey,
uint64  inKeyHash 
) const
inline

Find an element, returns null if not found.

◆ FromHandle()

template<class Key , class Value >
const LockFreeHashMap< Key, Value >::KeyValue * LockFreeHashMap< Key, Value >::FromHandle ( uint32  inHandle) const
inline

Convert uint32 handle back to key and value.

◆ GetAllKeyValues()

template<class Key , class Value >
void LockFreeHashMap< Key, Value >::GetAllKeyValues ( Array< const KeyValue * > &  outAll) const
inline

Get all key/value pairs.

◆ GetMaxBuckets()

template<class Key , class Value >
uint32 LockFreeHashMap< Key, Value >::GetMaxBuckets ( ) const
inline

Get the maximum amount of buckets that this map supports.

◆ GetNumBuckets()

template<class Key , class Value >
uint32 LockFreeHashMap< Key, Value >::GetNumBuckets ( ) const
inline

Get the current amount of buckets that the map is using.

◆ Init()

template<class Key , class Value >
void LockFreeHashMap< Key, Value >::Init ( uint32  inMaxBuckets)

Initialization

Parameters
inMaxBucketsMax amount of buckets to use in the hashmap. Must be power of 2.

◆ SetNumBuckets()

template<class Key , class Value >
void LockFreeHashMap< Key, Value >::SetNumBuckets ( uint32  inNumBuckets)

Update the number of buckets. This must be done after clearing the map and cannot be done concurrently with any other operations on the map. Note that the number of buckets can never become bigger than the specified max buckets during initialization and that it must be a power of 2.

◆ ToHandle()

template<class Key , class Value >
uint32 LockFreeHashMap< Key, Value >::ToHandle ( const KeyValue inKeyValue) const
inline

Get convert key value pair to uint32 handle.

Member Data Documentation

◆ cInvalidHandle

template<class Key , class Value >
const uint32 LockFreeHashMap< Key, Value >::cInvalidHandle = uint32(-1)
static

Value of an invalid handle.


The documentation for this class was generated from the following files: